Skip to content

HierarchyPlugin

Since v3.9.0

Hierarchy Plugin for tbw-grid

Builds one hierarchical row model from every attached structure contributor — TreePlugin discovers child rows, GroupingRowsPlugin groups sibling lists — and announces each row’s position with the WAI-ARIA treegrid pattern (aria-level / aria-setsize / aria-posinset).

Contributors know nothing about each other, so they compose: a grid with both Tree and GroupingRows groups the children of every tree level.

You never need to add this plugin yourself — TreePlugin and GroupingRowsPlugin declare it as a dependency and the grid attaches it automatically. It has no configuration.

import { TreePlugin } from '@toolbox-web/grid/plugins/tree';
import { GroupingRowsPlugin } from '@toolbox-web/grid/plugins/grouping-rows';
grid.gridConfig = {
plugins: [
new TreePlugin({ childrenField: 'children' }),
new GroupingRowsPlugin({
// Leave the root level ungrouped, group every child level by kind
groupOn: (row, { depth }) => (depth > 0 ? row.kind : null),
}),
],
};

Extends BaseGridPlugin

Inherited methods like attach(), detach(), afterRender(), etc. are documented in the base class.

Build the row model for a contributor’s processRows hook.

Every contributor forwards its hook here; only the one that runs last in the processRows pipeline builds the model (for all contributors at once) — the earlier ones pass their rows through untouched.

process(rows: readonly unknown[], caller: HierarchyContributor): unknown[]
NameTypeDescription
rowsreadonly unknown[]
callerHierarchyContributor
override processRows(rows: readonly unknown[]): unknown[] {
return this.grid.getPluginByName('hierarchy')?.process(rows, this) ?? [...rows];
}

Hierarchy position of a row in the current row model, or undefined when the row is not rendered (e.g. collapsed under a parent).

getRowMeta(row: unknown): HierarchyRowMeta | undefined
NameTypeDescription
rowunknown
const meta = grid.getPluginByName('hierarchy')?.getRowMeta(grid.rows[0]);
console.log(meta?.level, meta?.posInSet, meta?.setSize);