Skip to content

Column State & Updates

NextGrid lets you persist user column layouts independently of columnDefs and update column definitions atomically on a live grid.

// 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 defaults
grid.resetColumnState();

Individual setters (setColumnWidth, setColumnVisibility, setColumnPinned, setColumnFlex, moveColumn) update a single property and emit columnStateChanged.

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-adjusted width, 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 new minWidth/maxWidth, it clamps to the nearest bound.
  • Memoization Matters: Passing the exact same ColumnDef object 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: setColumnDefs throws without changing state if a removed column is still referenced by rowGrouping/treeData, cellSpans, rowSelection.checkboxColId, or columnGroups, or if column IDs/order change while pivot is enabled.