Search results

Get or Set Local Storage Value in React TreeGrid component

01 Feb 2023 / 1 minute to read

If the enablePersistence property is set to true, the treegrid 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.

Copied to clipboard
        // get the TreeGrid model.
        const value: string = window.localStorage.getItem('treegridTreeGrid') as string;
        // "treegridTreeGrid" is component name + component id.
        const model: object = JSON.parse(value);
Copied to clipboard
        // set the TreeGrid model.
        // "treegridTreeGrid" is component name + component id.
        window.localStorage.setItem('treegridTreeGrid', JSON.stringify(model));