Sowam
Sowam

Reputation: 1736

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?

Upvotes: 5

Views: 17530

Answers (2)

Sarun
Sarun

Reputation: 354

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,
       });

Upvotes: 7

NearHuscarl
NearHuscarl

Reputation: 81400

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

Upvotes: 14

Related Questions