Search results

State Persistence

State persistence refers to the Grid’s state maintained in the browser’s localStorage even if the browser is refreshed or if you move to the next page within the browser. State persistence stores grid’s model object in the local storage when the enablePersistence is defined as true.

Maintaining Custom Query in State Persistence

The grid does not maintain the query params after page load event when the enablePersistence is set to true. This is because the grid refreshes its query params for every page load. You can maintain the custom query params by resetting the addParams method in the actionBegin event.

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { GridComponent, Inject, ColumnsDirective, ColumnDirective, Filter, Page } from '@syncfusion/ej2-react-grids';
import { data } from './datasource';
class App extends React.Component<{}, {}>{
    private grid: GridComponent;
    public actionHandler(args){
        this.grid.query.addParams('$filter', 'EmployeeID eq 1');

    render() {
        return <GridComponent dataSource={data} allowFiltering={true} allowPaging={true} enablePersistence={true} height={230}
        actionBegin={this.actionHandler.bind(this)} ref={g => this.grid = g}>
                <ColumnDirective field='OrderID' width='100' textAlign="Right"></ColumnDirective>
                <ColumnDirective field='CustomerID' width='100'></ColumnDirective>
                <ColumnDirective field='EmployeeID' width='100' textAlign="Right"></ColumnDirective>
                <ColumnDirective field='Freight' width='100' format="C2" textAlign="Right"></ColumnDirective>
                <ColumnDirective field='ShipCountry' width='100'></ColumnDirective>
            <Inject services={[Filter, Page]} />
ReactDOM.render(<App />, document.getElementById('grid'));

How to get or set localStorage value

If the enablePersistence property is set to true, the grid property value is saved in the window.localStorage for reference. You can get/set the localStorage value by using the getItem/setItem method in the window.localStorage.

//get the Grid model.
let value: string = window.localStorage.getItem('gridGrid'); //"gridGrid" is component name + component id.
let model: Object = JSON.parse(model);
//set the Grid model.
window.localStorage.setItem('gridGrid', JSON.stringify(model)); //"gridGrid" is component name + component id.