New to KendoReact? Start a free 30-day trial

Persist and reset Grid column order and width in localStorage

Updated on Sep 2, 2026

Environment

Product Version16.1.0
ProductProgress® KendoReact Grid

Description

I want to persist the order and width of KendoReact Grid columns when users resize or reorder them. My columns are generated by a custom hook from a configuration array, and I want to restore the original configuration order when needed.

This KB also answers the following questions:

  • How do I persist KendoReact Grid column order and widths in localStorage when columns are generated by a custom hook?
  • How can I load saved Grid column state without refreshing the page?
  • How do I reset persisted Grid column order and render columns in their original configuration order?

Solution

Use the Grid columnsState prop to control column width and order. Keep the configuration array as the source of truth for column declarations, and persist the state collection separately. The Grid state contains the current field, width, and orderIndex values after a column is resized or reordered. The Grid uses smaller orderIndex values first, so you do not need to sort the configuration array. For more information, see the orderIndex property.

The following example demonstrates how to persist and reset KendoReact Grid column order and width in localStorage when columns are generated by a custom hook.

Example
View Source
Loading ...

To implement the solution, follow these steps:

  1. Define the columns with stable id values. The Grid uses the IDs to associate the persisted state with each declared column.

    tsx
    const columnConfig = [
        { id: 'product-id', field: 'ProductID', width: 200 },
        { id: 'product-name', field: 'ProductName', width: 200 },
        { id: 'category', field: 'Category', width: 200 },
        { id: 'unit-price', field: 'UnitPrice', width: 200 },
        { id: 'units-in-stock', field: 'UnitsInStock', width: 200 }
    ];
  2. Create the initial state from the configuration array. It establishes the original width and order that the reset action will restore.

    tsx
    const createInitialColumnsState = (config) =>
        config.map((column, orderIndex) => ({
            id: column.id,
            field: column.field,
            width: column.width,
            orderIndex
        }));
  3. Pass the state collection to the Grid and update it through onColumnsStateChange. This keeps the current column order and width in React state.

    tsx
    const [columnsState, setColumnsState] = React.useState(() => createInitialColumnsState(columnConfig));
    
    <Grid
        columnsState={columnsState}
        onColumnsStateChange={(event) => setColumnsState(event.columnsState)}
        reorderable={true}
        resizable={true}
    >
        {columnConfig.map((column) => (
            <GridColumn key={column.id} {...column} />
        ))}
    </Grid>
  4. Save and load columnsState when the user requests it. Loading replaces the controlled state, so the Grid immediately applies the saved column widths and order without a page refresh.

    tsx
    const saveColumnState = () => {
        localStorage.setItem('grid-columns-state', JSON.stringify(columnsState));
    };
    
    const loadColumnState = () => {
        const savedState = localStorage.getItem('grid-columns-state');
    
        if (savedState) {
            setColumnsState(JSON.parse(savedState));
        }
    };
  5. Restore the initial order by replacing columnsState with the state derived from the original configuration array. Select Save afterward if the reset state should persist across future page loads.

    tsx
    const resetColumnOrder = () => {
        setColumnsState(createInitialColumnsState(columnConfig));
    };

See Also

In this article
EnvironmentDescriptionSolutionSee Also
Not finding the help you need?
Contact Support