According to ag-grid, the column order will follow the order they were specified in column definitions. Reference
But this is not working when working with ag-grid-angular. Some columns are showing up first, even though they were specified at the end of the column definitions. Take a look at some example codes,
// grid.ts
// helper function to generate a definition of a single column
function generateColDef() {
return { ... };
}
// helper function to dynamically generate ColDefs
export function getColDef(someArgs) {
const someDynamicCols = someArgs.map((arg) => {
return generateColDef(.....);
})
const colDefs = [
slColumn, // A column to show serial number
generateColDef('id', 'ID', {
editable: false,
}),
generateColDef('name', 'Name', {
editable: false,
}),
...someDynamicCols,
];
return colDefs;
}
// html
<ag-grid-angular [columnDefs]="colDefs" [rowData]="rowData | async">
// component
args = { some args fetched from server }
colDefs = grid.getColDef(args);
rowData = { some data fetched from server }
What I expect is that the 'ID' and 'Name' columns will show first and then the rest of the someDynamicCols
will be displayed. But ag-grid sometimes displays the someDynamicCols
first and then the 'ID' and 'Name' columns.
I tried using the ag-grid API to set colDefs instead of using 2-way binding but the result stayed the same.
Can someone explain what the issue might be? Is it the ag-grid API or am I doing something wrong?
I am using the latest ag-grid (24.0.0) with angular 10