Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get and set ag-grid state?

Tags:

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.

like image 391
pupeno Avatar asked Mar 15 '17 13:03

pupeno


1 Answers

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'); } 
like image 63
Hamid Avatar answered Oct 19 '22 23:10

Hamid