React Data GridGrid State
react logo

This section covers saving and restoring the grid state, such as the filter model, selected rows, etc.

Saving and Restoring State

The initial state is provided via the grid option initialState. It is only read once when the grid is created.

const initialState = {
    filter: {
        filterModel: { 
            year: {
                filterType: 'set',
                values: ['2012'],
            }
        }
    },
    columnVisibility: {
        hiddenColIds: ['athlete'],
    },
    rowGroup: {
        groupColIds: ['athlete'],
    }
};

<AgGridReact initialState={initialState} />

The current grid state can be retrieved by listening to the state updated event, which is fired with the latest state when it changes, or via api.getState().

The state is also passed in the Grid Pre-Destroyed Event, which can be used to get the state when the grid is destroyed.

State Contents

The following is captured in the grid state:

Note that all the state properties are optional, so a property can be excluded if you do not want to restore it.

Properties available on the GridState interface.