Angular Data GridGrid State

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.

<ag-grid-angular
    [initialState]="initialState"
    /* other grid options ... */ />

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

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:

When restoring current page using the Server Side Row Model or Infinite Row Model additional configuration is required:

  • For the Server Side Row Model - set the serverSideInitialRowCount property to a value which includes the rows to be shown.
  • For the Infinite Row Model - set the infiniteInitialRowCount property to a value which includes the rows to be shown.

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

Properties available on the GridState interface.