How can I obtain and re-set the state of an ag-grid table? I mean, which columns are being show, in what order, with what sorting and filtering, etc.
Update: getColumnState and setColumnState seem to be close to what I want, but I cannot figure out the callbacks in which I should save and restore the state. I tried restoring it in onGridReady but when the actual rows are loaded, I lose the state.
There is a very specific example on their website providing details for what you are trying to do: javascript-grid-column-definitions
function saveState() { window.colState = gridOptions.columnApi.getColumnState(); window.groupState = gridOptions.columnApi.getColumnGroupState(); window.sortState = gridOptions.api.getSortModel(); window.filterState = gridOptions.api.getFilterModel(); console.log('column state saved'); }
and for restoring:
function restoreState() { gridOptions.columnApi.setColumnState(window.colState); gridOptions.columnApi.setColumnGroupState(window.groupState); gridOptions.api.setSortModel(window.sortState); gridOptions.api.setFilterModel(window.filterState); console.log('column state restored'); }
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