Skip to content

GridState

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.

export interface GridState {
readonly version: 5;
readonly sort: SortModel;
readonly filters: FilterModel;
readonly quickFilter: string;
readonly pagination: Readonly<PaginationState>;
readonly columns: Readonly<ColumnState>;
readonly hierarchy: Readonly<HierarchyState>;
readonly selection: Readonly<SelectionState | SelectionStateV3>;
readonly pivot: Readonly<PivotState>;
readonly details: Readonly<DetailState>;
readonly pinnedTotals: false | Readonly<PinnedTotalsOptions>;
readonly focus: Readonly<GridStateFocus>;
readonly dormantColumns: readonly Readonly<PivotDormantColumnState>[];
readonly suspended: Readonly<SuspendedGridViewState> | null;
}
export interface CurrentGridStatePatch extends Partial<Omit<GridState, 'version'>> {
readonly version: 5;
}
export interface ColumnStateItem {
readonly colId: string;
readonly width: number;
readonly isVisible: boolean;
readonly pinned: ColumnPin;
readonly flex: number | null;
}
export interface ColumnState {
readonly version: 1;
readonly columns: readonly Readonly<ColumnStateItem>[];
}
  • SelectionStateV1 (version: 1): Legacy flat row IDs and cell key ranges (accepted by applyState for GridStateV3).
  • SelectionState / SelectionStateV2 (version: 2): Current non-pivot selection storing rowIds, ranges (CellRangeState), and row cohorts (ids, sourceIntervals, or hierarchy).
  • SelectionStateV3 (version: 3): Stores PivotCellRangeState when client or server pivot mode is active.
  • HierarchyState: Either { mode: 'flat' } or { mode: 'group' | 'tree', columns, valueColumns, aggregationScope, groupTotals, grandTotal, expansion: { defaultExpandedDepth, overrides } }.
  • PivotState: Stores active pivot configuration, row/column dimensions, measures, totals, and expanded pivot group keys; inactive source-view columns/selection/sort/focus are preserved in suspended (SuspendedGridViewState) and dormantColumns while pivot is enabled.

Legacy Versions (v1–v4) & GridStatePatch

Section titled “Legacy Versions (v1–v4) & GridStatePatch”

GridStatePatch accepts version: 5 (CurrentGridStatePatch) as well as legacy patches from earlier versions:

  • version: 1 (LegacyGridStatePatch): sort, filters, quickFilter, pagination
  • version: 2 (GridStateV2Patch): v1 + columns
  • version: 3 (GridStateV3Patch): v2 + selection (SelectionStateV1)
  • version: 4 (GridStateV4Patch): v2 + hierarchy + selection (SelectionState)

Omitted fields in a patch keep their current runtime values. Candidate states are validated atomically before publication so invalid patches never leave half-applied state.

GridState never contains row payloads (rowData), mounted child grids, DOM nodes, remote block caches, measured row-height caches, supplied pinnedRows, cellSpans, or runtime callbacks (valueGetter, formatter, aggregateFunctions, detail.renderer). Reinstall matching callbacks and columnDefs before calling applyState.