Using Ag-Grid, users can drag columns to order them the way they like. I need to allow the user to save their column order (to an SQL backend) so that it becomes the default column order for them. I was trying to get the column names like this:
var cols = schedGridOptions.columnApi.getAllColumns();
for (col in cols) {
var colDef = col.getColDef();
console.log(colDef.headerName);
}
This was an example I found for setting the header name, so I tried to adapt it to getting the header name. But I get this error:
JavaScript runtime error: Object doesn't support property or method 'getColDef'
Perhaps I'm not doing this correctly? I'm fairly new at using Ag-Grid. Looking for suggestions.
In order for the Column Order to be maintained, the grid needs to match the Columns. This can be done by ensuring each Column has a field or colId defined.
Refresh Cells: api. refreshCells(cellRefreshParams) - Gets the grid to refresh all cells. Change detection will be used to refresh only cells whose display cell values are out of sync with the actual value. If using a cellRenderer with a refresh method, the refresh method will get called.
Update the Row Data inside the grid by updating the rowData grid property or by calling the grid API setRowData() .
To change the default action to use the Ctrl key (or Command key on Apple) instead set the property multiSortKey='ctrl' . The example below demonstrates the following: The grid sorts by Country then Athlete by default.
onColumnMoved
will fire every time the column is moving but the drag didn't stopped.
Using onColumnMoved
is not performant at all.
If you care about performance you should use onDragStopped
gridOptions.onDragStopped = function (params) {
const colIds = params.columnApi.getAllDisplayedColumns().map(col => col.colId)
console.log(colIds) // all visible colIds with the visible order
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With