Skip to content

Hierarchy API

GridApi<T> inherits HierarchyApi<T>, providing methods to inspect display nodes, toggle expansion, and persist state.

import { decodeHierarchyKey, encodeHierarchyKey } from 'next-grid-js';
const node = grid.getDisplayedRowNode(0);
if (node?.kind === 'group') {
grid.setGroupExpanded({ kind: 'node', key: node.key }, true);
grid.ensureDisplayNodeVisible({ kind: 'node', key: node.key }, 'start');
}
grid.expandAllGroups();
grid.collapseAllGroups();
const counts = grid.getHierarchyCounts();
const hierarchyState = grid.getGroupingState();
// Canonical key helpers
const encoded = encodeHierarchyKey('EMEA');
const original = decodeHierarchyKey(encoded);
  • DisplayNode<T> Kinds: 'leaf', 'tree' (hasData: true | false), 'group', and 'aggregate' (totalKind: 'groupTotal' | 'grandTotal').
  • State Persistence: getState() serializes hierarchy (mode, columns, valueColumns, aggregationScope, groupTotals, grandTotal, and expansion: { defaultExpandedDepth, overrides }). Always retain node.key (not nodeId) for structural commands.