# TreeOptions (@salmonui/data-grid/engine/tree)

> The TreeOptions interface of @salmonui/data-grid/engine/tree.

Canonical: https://salmonui.dev/docs/reference/data-grid/engine-tree/TreeOptions

```ts
import type { TreeOptions } from '@salmonui/data-grid/engine/tree';
```

Entry index: https://salmonui.dev/docs/reference/data-grid/engine-tree (Markdown with every symbol of the entry: https://salmonui.dev/docs/reference/data-grid/engine-tree.md).

## Reference

Kind: interface

```ts
interface TreeOptions<Row = unknown> {
    readonly childrenField?: string;
    readonly parentIdField?: string;
    readonly hasChildrenField?: string;
    readonly expandedField?: string;
    readonly column?: string;
    readonly defaultExpanded?: boolean | number;
    readonly expandedRows?: Readonly<Record<RowId, boolean>>;
    readonly filterMode?: TreeFilterMode;
    readonly pageBy?: TreePageBy;
    readonly checkbox?: boolean | {
        readonly cascade?: TreeCascade;
    };
    readonly copyMode?: TreeFilterMode;
    readonly childSummary?: boolean;
    readonly loadChildren?: (ctx: TreeLoadContext<Row>) => readonly Row[] | Promise<readonly Row[]>;
    readonly setParentId?: (row: Row, parentId: RowId | null) => Row;
    readonly hasChildren?: (row: Row, rowId: RowId) => boolean | undefined;
    readonly parentIdOf?: (row: Row, rowId: RowId) => RowId | null | undefined;
}
```

Members (16):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `childrenField` | `readonly childrenField?: string;` | optional | Nested rows: the field holding child arrays (`tree: true` means `'children'`). The engine source must be `flattenTree(data, childrenField)`. |
| `parentIdField` | `readonly parentIdField?: string;` | optional | Flat self-referential rows: the field holding the parent's row id (root: missing, null, `''`, or unknown). |
| `hasChildrenField` | `readonly hasChildrenField?: string;` | optional | Rows whose children load on demand (`hasChildMapping`). |
| `expandedField` | `readonly expandedField?: string;` | optional | Initial expansion from a boolean data field (`expandStateMapping`); overridden by `expandedRows` and every expand command. |
| `column` | `readonly column?: string;` | optional | Field or column id of the tree column (default: the first visible data column; resolved by the renderer). |
| `defaultExpanded` | `readonly defaultExpanded?: boolean \| number;` | optional | `true` (default): every parent expanded; `false`: collapsed; `n`: rows of depth < n expanded. |
| `expandedRows` | `readonly expandedRows?: Readonly<Record<RowId, boolean>>;` | optional | Initial per-row overrides over `defaultExpanded` (reactive input through `tree.setExpanded`). |
| `filterMode` | `readonly filterMode?: TreeFilterMode;` | optional | Rows a filter or search keeps: matches with their ancestors (default), with their descendants, both, or matches only (re-parented). |
| `pageBy` | `readonly pageBy?: TreePageBy;` | optional | Paging counts every visible row (default) or root rows with their subtrees. |
| `checkbox` | `readonly checkbox?: boolean \| {     readonly cascade?: TreeCascade; };` | optional | Checkbox in the tree column; `cascade` selects subtrees (`'filtered'`: kept rows only). |
| `copyMode` | `readonly copyMode?: TreeFilterMode;` | optional | Rows `copy()` adds around the copied rows (clipboard, read by the renderer). |
| `childSummary` | `readonly childSummary?: boolean;` | optional | Child summary rows (`__tf:<rowId>`) after the last visible descendant of each expanded parent (`showChildSummary`). |
| `loadChildren` | `readonly loadChildren?: (ctx: TreeLoadContext<Row>) => readonly Row[] \| Promise<readonly Row[]>;` | optional | Loads the children of a lazy row (`hasChildrenField`). Returned rows join the data source (local sources) under the row. |
| `setParentId` | `readonly setParentId?: (row: Row, parentId: RowId \| null) => Row;` | optional | Copy of a row with a new parent (flat data writes). Default: a shallow copy with `parentIdField` set. |
| `hasChildren` | `readonly hasChildren?: (row: Row, rowId: RowId) => boolean \| undefined;` | optional | Whether a row has children to load when `hasChildrenField` cannot be read (remote envelopes, tuple rows; `createRemoteTree`). `undefined` falls back to `hasChildrenField`. |
| `parentIdOf` | `readonly parentIdOf?: (row: Row, rowId: RowId) => RowId \| null \| undefined;` | optional | Parent row id of a row when the data does not carry it (remote envelopes, tuple rows; `createRemoteTree`); null: a root, `undefined`: fall back to `parentIdField` (or the nesting). Setting it reads parents as flat data. |
