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…?

duplicate-columns duplicate-columns-2

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 10
  • Comments: 27 (1 by maintainers)

Commits related to this issue

Most upvoted comments

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,

If you are updating the columns (not replacing the entire set) then you must either provide column ID’s or reuse the column definition object instances. Otherwise the grid will not know that the columns are in fact the same columns.

The right fix here as mentioned in the docs is to assign unqiue colId to columns, I have verified in the latest version; providing distinct colId when passing columns to setColumnDefs method, fixes this. I guess they could have highlighted this more.

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 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 under gridOptions.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,

We are aware of this issue and have a feature request in our backlog

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 missing colId value

I foresee that following means that can be undertaken to improve the current state of the things:

  1. colId field in Typescript ColDef type definition file shall be marked as mandatory, not as optional

image

  1. ag-grid could issue a warning in the browser console using console.warn level when when column definition does not have unique colId provided and one of the following column operation ( column resize, reorder, sort, filter, pinning, aggregation) occurs.

  2. if colId will remain optional in ColDef object definition then ag-grid shall be capable to use field data as fallback if no colId value is defined at ColDef

@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' }