ag-grid: Column IDs incorrect after dynamic columnDefs update (v19+ regression)
Using latest of all packages (19.1.x), dynamic column defs are really broken compared to v18. I believe this is related to the order also breaking - https://github.com/ag-grid/ag-grid/issues/2874
If we have two sets of defs which share some columns like this:
const simpleGrid = [
status,
columnDefs.causeAction,
isin,
...
];
const richGrid = [
status,
isin,
...
];
export default function gridConfig(isRichView) {
return isRichView ? richGrid : simpleGrid;
}
<AgGridReact
columnDefs={gridConfig(hasRichGridConfig)}
...
/>
If we toggle these defs
(a) Sometimes the order completely breaks unless we deep copy to new refs (see #2874)
(b) col-id
becomes incorrect due to appending _1
and breaks QA tests. Seems like AG is keeping the previous column internally and considers this a copy…?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 10
- Comments: 27 (1 by maintainers)
this.gridApi.setColumnDefs([]); this.gridApi.setColumnDefs(this.columnDefs);
@BobrImperator apart from performance hit this will also clear any column resize, reorder, sort, filter, pinning, aggregation, row group or pivots applied by the user. and frankly that won’t translate into a great user experience.
Also Ag-grid’s documentation for column definition states,
The right fix here as mentioned in the docs is to assign unqiue
colId
to columns, I have verified in the latest version; providing distinctcolId
when passing columns tosetColumnDefs
method, fixes this. I guess they could have highlighted this more.I personally handle this by resetting columnDefs completely, before I apply dynamically loaded colDefs, I clear the definitions first by giving empty array to
setColumnDefs
. I do that only if list reference is different than the old one, which is saved undergridOptions.columnApi.colDefs
key. That way I don’t have to worry about filtering, sorting or any operations that rely on colId, although I do take a certain performance hit.Hi, AG Grid Team,
I am using the latest AG Grid, and figure out this issue is still in the latest version 21.1.0. When I set a new columnDefs with same field id, the field id is appended with _1.
This affects our filtering and sorting functions.
So, this bug is not closed. Please give us hint on how to deal with it.
Thanks!
I have the same problem on an angular app using the grid’s version 21.0.1. I am saving the state of the columns and when I call “gridOptions.columnApi.getColumnState()” it gives me columns with “_1” appended to the colId which I am using as a reference
@DominicTobias I opened a similar issue #2846 , turns out this started appearing from 19.1.1 or 19.1.2, I believe at the time when I did some digging around this I found that this started appearing after AG-1591. basically Providing a new column with the same name but different ref as of before makes the grid think this is a new column and tries to generate a new unique incremented colId for the column.
this is the response I got,
AG-2289 | Delta Columns - Investigate if it we should consider setColumnDefs as the golden source for delta columns. | BACKLOG | | | More Info | AG-1559 | Allow delta updates to column definitions, this should include all CRUD operations | BACKLOG
AG-2289 appears to be part of next release and I’m unable to track AG-1559 neither in the pipeline nor in the change log.
yes colId fixed the _1 issue but the grid the group by breaks if you added rowGroup with colId to col definition.
I think
ag-grid
can do better about signalling that supplied column definition object is missingcolId
valueI foresee that following means that can be undertaken to improve the current state of the things:
colId
field in TypescriptColDef
type definition file shall be marked as mandatory, not as optionalag-grid could issue a warning in the browser console using
console.warn
level when when column definition does not have uniquecolId
provided and one of the following column operation ( column resize, reorder, sort, filter, pinning, aggregation) occurs.if
colId
will remain optional inColDef
object definition then ag-grid shall be capable to usefield
data as fallback if nocolId
value is defined atColDef
@Earthwormzim That can work in some instances! Glad it solved your problem
I was also having the same problem. I solved it by adding “colId” to the column definition. i.e.:
{ headerName: 'My Awesome Column', field: 'myColumnId', colId: 'myColumnId' }