# HierarchyPlugin

> _Since v3.9.0_

Hierarchy Plugin for tbw-grid

Builds one hierarchical row model from every attached structure contributor
— [`TreePlugin`](https://toolboxjs.com/grid/plugins/tree/classes/treeplugin.md) discovers
child rows, [`GroupingRowsPlugin`](https://toolboxjs.com/grid/plugins/grouping-rows/classes/groupingrowsplugin.md)
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.

## Example

### Group the children of every tree node

```ts
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](https://toolboxjs.com/grid/api/plugin-development/classes/basegridplugin.md)
>
> Inherited methods like `attach()`, `detach()`, `afterRender()`, etc. are documented in the base class.

## Methods

### process() <span class="since-badge" title="Introduced in v3.9.0">v3.9.0+</span>

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.

```ts
process(rows: readonly unknown[], caller: HierarchyContributor): unknown[]
```

#### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| `rows` | <code>readonly unknown[]</code> |  |
| `caller` | <code><a href="/grid/plugins/hierarchy/interfaces/hierarchycontributor/">HierarchyContributor</a></code> |  |

#### Example

```ts
override processRows(rows: readonly unknown[]): unknown[] {
  return this.grid.getPluginByName('hierarchy')?.process(rows, this) ?? [...rows];
}
```

***

### getRowMeta() <span class="since-badge" title="Introduced in v3.9.0">v3.9.0+</span>

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

```ts
getRowMeta(row: unknown): HierarchyRowMeta | undefined
```

#### Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| `row` | <code>unknown</code> |  |

#### Example

```ts
const meta = grid.getPluginByName('hierarchy')?.getRowMeta(grid.rows[0]);
console.log(meta?.level, meta?.posInSet, meta?.setSize);
```

***
