# @salmonui/data-grid/engine/tree-remote API reference

> 8 exported symbols of @salmonui/data-grid/engine/tree-remote: 2 functions and 6 interfaces.

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

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

## Functions

### bindRemoteTree

Kind: function

Page: https://salmonui.dev/docs/reference/data-grid/engine-tree-remote/bindRemoteTree

```ts
function bindRemoteTree<Row>(source: DataSource<Row>, options: RemoteTreeOptions<Row>, { createTreeModule, serializeDataGridQuery }: RemoteTreeDeps): RemoteTree<Row>;
```

Not for apps (use `createRemoteTree`): `createRemoteTree` over injected functions.

### createRemoteTree

Kind: function

Page: https://salmonui.dev/docs/reference/data-grid/engine-tree-remote/createRemoteTree

```ts
function createRemoteTree<Row>(source: DataSource<Row>, options: RemoteTreeOptions<Row>): RemoteTree<Row>;
```

Adapts a remote source with tree reads (`read({ parentRowId })`) to tree
mode. Register `module(treeOptions)` and read through `dataSource`.

## Interfaces

### RemoteTree

Kind: interface

Page: https://salmonui.dev/docs/reference/data-grid/engine-tree-remote/RemoteTree

```ts
interface RemoteTree<Row> {
    readonly dataSource: DataSource<Row>;
    module(options?: TreeOptions<Row>): TreeModule<Row>;
    getLoadError(rowId: RowId): unknown;
    loadMoreRoots(): Promise<boolean>;
    getRootBlocks(): RemoteTreeRootBlocks;
}
```

Members (5):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `dataSource` | `readonly dataSource: DataSource<Row>;` |  | The engine's `dataSource` (`mode: 'remote'`). |
| `module` | `module(options?: TreeOptions<Row>): TreeModule<Row>;` |  | The tree module to register instead of `createTreeModule(options)` (call once per engine). |
| `getLoadError` | `getLoadError(rowId: RowId): unknown;` |  | Error of the last failed child load of a row, or undefined. |
| `loadMoreRoots` | `loadMoreRoots(): Promise<boolean>;` |  | `rootBlocks`: reads the next block of root rows and appends it (one read at a time). Resolves true when rows were appended; false when there is nothing to read, a read is in flight, or a query change superseded it. Rejects when the read fails. |
| `getRootBlocks` | `getRootBlocks(): RemoteTreeRootBlocks;` |  | `rootBlocks` state (`hasMore` is false without `rootBlocks`). |

### RemoteTreeDeps

Kind: interface

Page: https://salmonui.dev/docs/reference/data-grid/engine-tree-remote/RemoteTreeDeps

```ts
interface RemoteTreeDeps {
    readonly createTreeModule: typeof createTreeModule;
    readonly serializeDataGridQuery: (query: DataQuery) => string;
}
```

What `bindRemoteTree` is given instead of importing it.

Members (2):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `createTreeModule` | `readonly createTreeModule: typeof createTreeModule;` |  |  |
| `serializeDataGridQuery` | `readonly serializeDataGridQuery: (query: DataQuery) => string;` |  |  |

### RemoteTreeEnvelope

Kind: interface

Page: https://salmonui.dev/docs/reference/data-grid/engine-tree-remote/RemoteTreeEnvelope

```ts
interface RemoteTreeEnvelope<Row> {
    readonly kind: 'tree';
    readonly row: Row;
    readonly parentId?: RowId | null;
    readonly depth?: number;
    readonly hasChildren?: boolean;
    readonly childCount?: number;
    readonly children?: readonly RemoteTreeEnvelope<Row>[];
}
```

A tree read item (structural copy of `@salmonui/data` `TreeRowEnvelope`; `depth` is informational).

Members (7):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `kind` | `readonly kind: 'tree';` |  |  |
| `row` | `readonly row: Row;` |  |  |
| `parentId` | `readonly parentId?: RowId \| null;` | optional | Parent of the row (null: a root). Default: the requested parent, or the envelope holding it in `children`. |
| `depth` | `readonly depth?: number;` | optional |  |
| `hasChildren` | `readonly hasChildren?: boolean;` | optional |  |
| `childCount` | `readonly childCount?: number;` | optional |  |
| `children` | `readonly children?: readonly RemoteTreeEnvelope<Row>[];` | optional | Children loaded with the row (load all, nested remote data); `[]` means a leaf. |

### RemoteTreeError

Kind: interface

Page: https://salmonui.dev/docs/reference/data-grid/engine-tree-remote/RemoteTreeError

```ts
interface RemoteTreeError {
    readonly action: 'treeChildren';
    readonly rowId: RowId;
    readonly error: unknown;
}
```

A failed child load (`onError` with `action: 'treeChildren'` in the React layer).

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `action` | `readonly action: 'treeChildren';` |  |  |
| `rowId` | `readonly rowId: RowId;` |  |  |
| `error` | `readonly error: unknown;` |  |  |

### RemoteTreeOptions

Kind: interface

Page: https://salmonui.dev/docs/reference/data-grid/engine-tree-remote/RemoteTreeOptions

```ts
interface RemoteTreeOptions<Row> {
    readonly getRowId: (row: Row, index: number) => RowId;
    readonly onError?: (event: RemoteTreeError) => void;
    readonly rootBlocks?: {
        readonly blockSize?: number;
        readonly initialBlocks?: number;
    };
}
```

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `getRowId` | `readonly getRowId: (row: Row, index: number) => RowId;` |  | The grid's `getRowId`. |
| `onError` | `readonly onError?: (event: RemoteTreeError) => void;` | optional | Called once per failed child load (not for aborted loads). |
| `rootBlocks` | `readonly rootBlocks?: {     readonly blockSize?: number;     readonly initialBlocks?: number; };` | optional | Infinite scroll in tree mode: read the root rows in blocks of `blockSize` (default 100; `range` over the root level), `initialBlocks` (default 3) on the first read, the next block on `loadMoreRoots()`. Ignored while the query pages (`pageBy: 'root'` paging). |

### RemoteTreeRootBlocks

Kind: interface

Page: https://salmonui.dev/docs/reference/data-grid/engine-tree-remote/RemoteTreeRootBlocks

```ts
interface RemoteTreeRootBlocks {
    readonly loadedRoots: number;
    readonly hasMore: boolean;
    readonly loading: boolean;
}
```

Root block state of `rootBlocks`.

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `loadedRoots` | `readonly loadedRoots: number;` |  | Root rows read so far (the offset of the next block). |
| `hasMore` | `readonly hasMore: boolean;` |  | More root rows may follow. |
| `loading` | `readonly loading: boolean;` |  | A block read is in flight. |
