Column State & Updates
NextGrid lets you persist user column layouts independently of columnDefs and update column definitions atomically on a live grid.
Saving & Restoring ColumnState
Section titled “Saving & Restoring ColumnState”// Full snapshot (width, isVisible, pinned, flex, order)const snapshot = grid.getColumnState();grid.applyColumnState(snapshot);
// Partial patch (update widths/visibility without touching other columns)grid.applyColumnStatePatch({ version: 1, applyOrder: false, columns: [{ colId: 'price', width: 140, isVisible: true }],});
// Reset layout back to current columnDefs defaultsgrid.resetColumnState();Individual setters (setColumnWidth, setColumnVisibility, setColumnPinned, setColumnFlex, moveColumn) update a single property and emit columnStateChanged.
Updating Definitions with setColumnDefs
Section titled “Updating Definitions with setColumnDefs”setColumnDefs(columnDefs, options?) replaces columnDefs (and optionally columnGroups and defaultColDef via ColumnDefinitionsUpdate) in one synchronous transaction:
grid.setColumnDefs( [ { colId: 'customer', key: 'customer', name: 'Client' }, { colId: 'amount', key: 'amount', isSortable: true }, ], { columnGroups: [{ groupId: 'order', name: 'Order', children: ['customer', 'amount'] }], },);- Matched by
colId: Kept columns preserve user-adjustedwidth,flex,isVisible,pinned, and order (definition layout fields on kept columns are ignored so re-renders never undo a resize). If a kept width falls outside newminWidth/maxWidth, it clamps to the nearest bound. - Memoization Matters: Passing the exact same
ColumnDefobject reference avoids reprocessing. Changing value functions (key,valueGetter,cellDataType,formatter,comparator,filterPredicate,quickFilterTextGetter) reruns client processing and clears undo history. - Pruning Removed Columns: Sort entries, filter entries, cell ranges, and focus referencing removed columns are pruned atomically; open column menus close.
- Refused Calls:
setColumnDefsthrows without changing state if a removed column is still referenced byrowGrouping/treeData,cellSpans,rowSelection.checkboxColId, orcolumnGroups, or if column IDs/order change whilepivotis enabled.