Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AgGrid: applyColumnState is not a function

I am using ag-grid in my project and I have problem with applying state of table. Here is my code fragment from onGridReady function:

 this.gridApi = params.api;
    this.gridColumnApi = params.columnApi;

    if (!window.colState) {
        console.log("no columns state to restore by, you must save state first");
    } else {
        this.gridColumnApi.applyColumnState({
            state: window.colState,
            applyOrder: true,
        });
        console.log("column state restored");
    }

It is taken from ag-grid of course. Right under it I have this.gridColumnApi.getAllColumns() and this.gridColumnApi.autoSizeColumns() functions that works fine.

The problem is that this.gridColumnApi.applyColumnState gives me this error.

TypeError: _this.gridColumnApi.applyColumnState is not a function

I cannot understand why other functions called on this.gridColumnApi works but applyColumnState doesn't. Any suggestions?

@edit I even tried this one:

componentWillUnmount() {
    window.colState = this.props.gridColumnApi.getColumnState();
    console.log("column state saved");
    if (this.props.gridColumnApi.applyColumnState) {
        devLog("IT IS HERE");
    } else {
        devLog("its not");
    }
    this.gridColumnApi.resetColumnState();
    console.log("column state reset");
}

but I get applyColumnState and resetColumnState is not a function errors, what is wrong here?

like image 876
Sowam Avatar asked Sep 18 '20 10:09

Sowam


2 Answers

Check your AgGrid version. ColumnApi.applyColumnState() was added in version 24.0.0.

like image 106
NearHuscarl Avatar answered Oct 16 '22 09:10

NearHuscarl


If you are stuck with a lower ag-grid version (< 24.0.0), then use gridOptions.columnApi.setColumnState(prevState)

With ag-grid version 24.0.0 and above you can use -

gridOptions.columnApi.applyColumnState({
         state:prevState,
         applyOrder: true,
       });
like image 43
Sarun Avatar answered Oct 16 '22 10:10

Sarun