# TreeConfig

> _Since v0.1.1_

Configuration options for the tree plugin.

#### Example

```ts
const grid = document.querySelector('tbw-grid');
grid.plugins = [
  new TreePlugin({
    childrenField: 'subItems',
    defaultExpanded: true,
    indentWidth: 24,
    animation: 'slide',
  }),
];
```

## Properties

| Property | Type | Description |
| -------- | ---- | ----------- |
| <span id="childrenfield"></span>`childrenField?` | <code>string</code> | Field name containing child rows (default: 'children') |
| <span id="autodetect"></span>`autoDetect?` | <code>boolean</code> | Auto-detect tree structure from data (default: true) |
| <span id="defaultexpanded"></span>`defaultExpanded?` | <code>boolean</code> | Whether nodes are expanded by default (default: false) |
| <span id="indentwidth"></span>`indentWidth?` | <code>number</code> | Indentation width per level in pixels (default: 20) |
| <span id="showexpandicons"></span>`showExpandIcons?` | <code>boolean</code> | Show expand/collapse icons (default: true) |
| <span id="treecolumn"></span>`treeColumn?` | <code>string</code> | Field name of the column that displays the tree toggle and indentation. Defaults to the first visible column. Use this when the first column is narrow (e.g. an ID column) or when combining with pinned columns. |
| `animation?` | <code><a href="/grid/api/core/types/expandcollapseanimation/">ExpandCollapseAnimation</a></code> | Animation style for expanding/collapsing tree nodes. - `false`: No animation - `'slide'`: Slide animation (default) - `'fade'`: Fade animation |
| `loadChildren?` | <code>(params: <a href="/grid/plugins/tree/interfaces/treeloadchildrenparams/">TreeLoadChildrenParams</a>) =&gt; Promise&lt;<a href="/grid/plugins/tree/types/treerow/">TreeRow</a>[]&gt; &#124; <a href="/grid/plugins/server-side/interfaces/subscribable/">Subscribable</a>&lt;<a href="/grid/plugins/tree/types/treerow/">TreeRow</a>[]&gt;</code> | Lazy-load child rows when a node is expanded. <span class="since-badge" title="Introduced in v3.4.0">v3.4.0+</span> |
| `hasChildren?` | <code>(row: <a href="/grid/plugins/tree/types/treerow/">TreeRow</a>) =&gt; boolean</code> | Predicate deciding whether a node has children, used to render the expand toggle before the children are loaded. <span class="since-badge" title="Introduced in v3.4.0">v3.4.0+</span> |

### Property Details

#### `animation`

**Default:** `'slide'`

---

#### `loadChildren`

Lazy-load child rows when a node is expanded.

Called once per row object the first time it is expanded while its children
are not yet loaded — and again for a still-expanded node when the rows are
replaced with new objects (e.g. a new `grid.rows` array). The resolved rows
are written to `row[childrenField]` and the grid re-renders. While the
request is in flight the node's toggle is
replaced by the grid's small spinner and the row carries `aria-busy`.

Returns a `Promise` or a Subscribable (e.g. an Angular
`HttpClient` observable — the subscription is torn down on abort, which
natively cancels the underlying request).

Ignored when ServerSidePlugin is active —
child data then flows through `dataSource.getChildRows()` instead.

Pair with TreeConfig.hasChildren when unloaded nodes cannot be
detected from the data alone.

```ts
new TreePlugin({
  hasChildren: (row) => row.type === 'folder',
  loadChildren: async ({ row, signal }) => {
    const res = await fetch(`/api/nodes/${row.id}/children`, { signal });
    return res.json();
  },
})
```

---

#### `hasChildren`

Predicate deciding whether a node has children, used to render the expand
toggle before the children are loaded.

Defaults to the built-in heuristic: an array with entries means children
are embedded, any other truthy `row[childrenField]` value (e.g.
`children: true`) means children exist but are not loaded yet.

A node with a non-empty embedded children array always counts as having
children regardless of what this predicate returns. Never called for
ServerSide loading placeholders, which are always leaves.

---
