State Persistence
NextGrid exposes a JSON-serializable state snapshot (GridState, currently version 5) via getState() and restores full snapshots or partial patches via applyState(patch) and initialState.
Debounced Persistence (localStorage / Server)
Section titled “Debounced Persistence (localStorage / Server)”let timer: ReturnType<typeof setTimeout> | undefined;
grid.addEventListener('stateChanged', (event) => { if (event.source === 'stateRestore') return; // avoid redundant write on restore clearTimeout(timer); timer = setTimeout(() => { localStorage.setItem('orders-grid-v5', JSON.stringify(event.state)); }, 200);});
const saved = localStorage.getItem('orders-grid-v5');if (saved) { grid.applyState(JSON.parse(saved));}What Is Serialized vs. Excluded
Section titled “What Is Serialized vs. Excluded”- Serialized in v5:
sort,filters,quickFilter,pagination,columns(ColumnState),hierarchy(HierarchyState),selection(SelectionStatev2/v3),pivot,details,pinnedTotals,focus,dormantColumns, andsuspended. - Excluded: Row payloads (
rowData), mounted child grids, DOM nodes, remote caches, measured height caches, suppliedpinnedRows,cellSpans, and callbacks (valueGetter,formatter,aggregateFunctions,detail.renderer). Reinstall matching callbacks andcolumnDefsbefore callingapplyState.
Atomicity & Legacy Migration (v1–v4)
Section titled “Atomicity & Legacy Migration (v1–v4)”applyState accepts partial v5 patches and legacy version: 1..4 patches. Omitted groups stay intact, and candidate states validate atomically before publication so invalid patches throw without mutating live state.