# @salmonui/data-grid/engine/infinite API reference

> 24 exported symbols of @salmonui/data-grid/engine/infinite: 4 functions, 2 classes, 6 interfaces, 10 types and 2 constants.

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

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

## Functions

### createInfiniteScrollModule

Kind: function

Page: https://salmonui.dev/docs/reference/data-grid/engine-infinite/createInfiniteScrollModule

```ts
function createInfiniteScrollModule<Row>(options?: InfiniteScrollOptions<Row>): InfiniteScrollModule<Row>;
```

Infinite scroll for remote sources: the grid requests row ranges
(`DataSourceRequest.range`) as the viewport approaches rows that are not
loaded; see the module header for the scheduling rules.

### lazyGroupsToAppend

Kind: function

Page: https://salmonui.dev/docs/reference/data-grid/engine-infinite/lazyGroupsToAppend

```ts
function lazyGroupsToAppend(view: RowModelView | null | undefined, start: number, end: number, threshold?: number): RowId[];
```

Group row ids (`__g:` ids) whose next chunk should load for the rendered
rows `[start, end)` of `view`: expanded lazy groups with `hasMore`, not
loading and not failed, whose loaded content ends within `threshold` rows
past the window. Empty unless the base view is a lazy group view.

### loadingRowIndex

Kind: function

Page: https://salmonui.dev/docs/reference/data-grid/engine-infinite/loadingRowIndex

```ts
function loadingRowIndex(rowId: RowId): number;
```

Placeholder row index of a `__loading:<n>` id, or -1.

### resolveInfiniteOptions

Kind: function

Page: https://salmonui.dev/docs/reference/data-grid/engine-infinite/resolveInfiniteOptions

```ts
function resolveInfiniteOptions(o?: InfiniteScrollOptions<never>): ResolvedInfiniteOptions;
```

## Classes

### InfiniteStore

Kind: class

Page: https://salmonui.dev/docs/reference/data-grid/engine-infinite/InfiniteStore

```ts
class InfiniteStore<Row> {
    readonly options: ResolvedInfiniteOptions;
    blocks: ReadonlyMap<number, InfiniteBlock<Row>>;
    pending: ReadonlySet<number>;
    readonly index: Map<string, number>;
    total: number | null;
    totalKnown: boolean;
    hasMore: boolean;
    highest: number;
    active: boolean;
    seeded: boolean;
    status: InfiniteStatus;
    error: unknown;
    version: number;
    generation: number;
    loadedRows: number;
    stats: {
        requests: number;
        aborted: number;
        evicted: number;
    };
    constructor(options: ResolvedInfiniteOptions);
    count(): number;
    clear(): void;
    place(offset: number, rows: readonly Row[], getRowId: (row: Row, index: number) => RowId, info: PlaceInfo): void;
    drop(next: Map<number, InfiniteBlock<Row>>, b: number): void;
    setBlocks(next: ReadonlyMap<number, InfiniteBlock<Row>>): void;
    rowAt(index: number): Row | undefined;
}
```

Loaded blocks of the current query. `blocks` and `pending` are replaced on
every change (a view keeps the maps it was built from); `index` maps the
ids of loaded rows to their row index and is checked against the blocks.

Members (22):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `options` | `readonly options: ResolvedInfiniteOptions;` |  |  |
| `blocks` | `blocks: ReadonlyMap<number, InfiniteBlock<Row>>;` |  |  |
| `pending` | `pending: ReadonlySet<number>;` |  |  |
| `index` | `readonly index: Map<string, number>;` |  |  |
| `total` | `total: number \| null;` |  |  |
| `totalKnown` | `totalKnown: boolean;` |  | `total` came from the source (`totalRowCount`), not from reaching the end of an unknown total. |
| `hasMore` | `hasMore: boolean;` |  |  |
| `highest` | `highest: number;` |  | End of the highest loaded block. |
| `active` | `active: boolean;` |  |  |
| `seeded` | `seeded: boolean;` |  | Blocks came from `initialResult`; the first query keeps them. |
| `status` | `status: InfiniteStatus;` |  |  |
| `error` | `error: unknown;` |  |  |
| `version` | `version: number;` |  |  |
| `generation` | `generation: number;` |  |  |
| `loadedRows` | `loadedRows: number;` |  |  |
| `stats` | `stats: {     requests: number;     aborted: number;     evicted: number; };` |  |  |
| `count` | `count(): number;` |  | Rows of the view: the exact total, else the loaded end plus one loading row while more may follow. |
| `clear` | `clear(): void;` |  |  |
| `place` | `place(offset: number, rows: readonly Row[], getRowId: (row: Row, index: number) => RowId, info: PlaceInfo): void;` |  | Places result rows starting at row `offset`; complete blocks only (the last block of the data may be short). |
| `drop` | `drop(next: Map<number, InfiniteBlock<Row>>, b: number): void;` |  | Removes a block (eviction, refresh). |
| `setBlocks` | `setBlocks(next: ReadonlyMap<number, InfiniteBlock<Row>>): void;` |  |  |
| `rowAt` | `rowAt(index: number): Row \| undefined;` |  | Loaded row at a row index, or undefined. |

### InfiniteView

Kind: class

Page: https://salmonui.dev/docs/reference/data-grid/engine-infinite/InfiniteView

```ts
class InfiniteView<Row = unknown> implements RowModelView {
    readonly kind: 'infinite';
    readonly count: number;
    readonly dataCount: number;
    readonly status: InfiniteStatus;
    private readonly blocks;
    private readonly pending;
    private readonly store;
    private readonly B;
    constructor(store: InfiniteStore<Row>);
    private block;
    isLoaded(index: number): boolean;
    statusAt(index: number): 'loading' | 'error';
    kindAt(index: number): RowKind;
    sourceIndexAt(): number;
    idAt(index: number): RowId | undefined;
    depthAt(): number;
    indexOfSource(): number;
    parentOfSource(): RowId | null;
    resolve(id: RowId): ViewRowInfo | undefined;
}
```

Row model view over the loaded blocks: loaded rows are `data`, the others `loading` placeholders.

Members (18):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `kind` | `readonly kind: 'infinite';` |  |  |
| `count` | `readonly count: number;` |  |  |
| `dataCount` | `readonly dataCount: number;` |  |  |
| `status` | `readonly status: InfiniteStatus;` |  |  |
| `blocks` | `private readonly blocks;` |  |  |
| `pending` | `private readonly pending;` |  |  |
| `store` | `private readonly store;` |  |  |
| `B` | `private readonly B;` |  |  |
| `block` | `private block;` |  |  |
| `isLoaded` | `isLoaded(index: number): boolean;` |  | The row at `index` is loaded. |
| `statusAt` | `statusAt(index: number): 'loading' \| 'error';` |  | Placeholder state: `error` after a failed load of its block, else `loading`. |
| `kindAt` | `kindAt(index: number): RowKind;` |  |  |
| `sourceIndexAt` | `sourceIndexAt(): number;` |  |  |
| `idAt` | `idAt(index: number): RowId \| undefined;` |  |  |
| `depthAt` | `depthAt(): number;` |  |  |
| `indexOfSource` | `indexOfSource(): number;` |  |  |
| `parentOfSource` | `parentOfSource(): RowId \| null;` |  |  |
| `resolve` | `resolve(id: RowId): ViewRowInfo \| undefined;` |  |  |

## Interfaces

### InfiniteBlock

Kind: interface

Page: https://salmonui.dev/docs/reference/data-grid/engine-infinite/InfiniteBlock

```ts
interface InfiniteBlock<Row> {
    readonly rows: readonly Row[];
    readonly ids: readonly RowId[];
    readonly stale: boolean;
}
```

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `rows` | `readonly rows: readonly Row[];` |  |  |
| `ids` | `readonly ids: readonly RowId[];` |  |  |
| `stale` | `readonly stale: boolean;` |  | Re-requested after a structural write; still rendered until the reload lands. |

### InfiniteScheduler

Kind: interface

Page: https://salmonui.dev/docs/reference/data-grid/engine-infinite/InfiniteScheduler

```ts
interface InfiniteScheduler {
    now(): number;
    setTimeout(run: () => void, ms: number): unknown;
    clearTimeout(handle: unknown): void;
}
```

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `now` | `now(): number;` |  |  |
| `setTimeout` | `setTimeout(run: () => void, ms: number): unknown;` |  |  |
| `clearTimeout` | `clearTimeout(handle: unknown): void;` |  |  |

### InfiniteScrollOptions

Kind: interface

Page: https://salmonui.dev/docs/reference/data-grid/engine-infinite/InfiniteScrollOptions

```ts
interface InfiniteScrollOptions<Row = unknown> {
    readonly blockSize?: number;
    readonly initialBlocks?: number;
    readonly cache?: boolean;
    readonly maxBlocks?: number;
    readonly threshold?: number;
    readonly debounceMs?: number;
    readonly initialResult?: Pick<DataSourceResult<Row>, 'rows' | 'totalRowCount' | 'pageInfo'>;
    readonly scheduler?: InfiniteScheduler;
}
```

Members (8):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `blockSize` | `readonly blockSize?: number;` | optional | Rows per block and per request unit. Default 100. |
| `initialBlocks` | `readonly initialBlocks?: number;` | optional | Blocks of the first request. Default 3. |
| `cache` | `readonly cache?: boolean;` | optional | Bound the blocks held in memory to `maxBlocks`. Default false: every loaded block is kept. |
| `maxBlocks` | `readonly maxBlocks?: number;` | optional | Blocks kept with `cache`; never fewer than the viewport needs. Default 3. |
| `threshold` | `readonly threshold?: number;` | optional | Rows before the loaded end (and around the viewport) at which the next block is requested. Default half a block. |
| `debounceMs` | `readonly debounceMs?: number;` | optional | Quiet time before a request for a jump target (scrollbar drag, scrollTo) and between sequential requests. Default 50 ms. |
| `initialResult` | `readonly initialResult?: Pick<DataSourceResult<Row>, 'rows' \| 'totalRowCount' \| 'pageInfo'>;` | optional | The first blocks, already fetched (server render): rendered on the server and on the first client render, and not requested again. `rows` start at row 0. |
| `scheduler` | `readonly scheduler?: InfiniteScheduler;` | optional | Clock and timers (tests). Default `Date.now`, `setTimeout`, `clearTimeout`. |

### InfiniteScrollState

Kind: interface

Page: https://salmonui.dev/docs/reference/data-grid/engine-infinite/InfiniteScrollState

```ts
interface InfiniteScrollState {
    readonly active: boolean;
    readonly version: number;
    readonly generation: number;
    readonly status: InfiniteStatus;
    readonly error: unknown;
    readonly totalRowCount: number | null;
    readonly loadedRowCount: number;
    readonly hasMore: boolean;
}
```

The `infiniteScroll` module slice (`snapshot.modules.infiniteScroll`); replaced once per settled load.

Members (8):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `active` | `readonly active: boolean;` |  | The module serves the main read (remote source, no grouping). |
| `version` | `readonly version: number;` |  | Bumped whenever the loaded blocks change. |
| `generation` | `readonly generation: number;` |  | Bumped when the blocks are dropped for a new query (the renderer scrolls back to the top). |
| `status` | `readonly status: InfiniteStatus;` |  |  |
| `error` | `readonly error: unknown;` |  |  |
| `totalRowCount` | `readonly totalRowCount: number \| null;` |  | Exact row count: the source total, or the loaded end once the last block arrived; null while unknown. |
| `loadedRowCount` | `readonly loadedRowCount: number;` |  | Rows held in memory. |
| `hasMore` | `readonly hasMore: boolean;` |  | Unknown total only: more rows may follow the loaded end (a loading row is shown there). |

### InfiniteScrollStats

Kind: interface

Page: https://salmonui.dev/docs/reference/data-grid/engine-infinite/InfiniteScrollStats

```ts
interface InfiniteScrollStats {
    readonly requests: number;
    readonly aborted: number;
    readonly evicted: number;
}
```

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `requests` | `readonly requests: number;` |  | Range reads issued. |
| `aborted` | `readonly aborted: number;` |  | Reads aborted because the viewport moved away (stale) or the query changed. |
| `evicted` | `readonly evicted: number;` |  | Blocks evicted beyond `maxBlocks`. |

### ResolvedInfiniteOptions

Kind: interface

Page: https://salmonui.dev/docs/reference/data-grid/engine-infinite/ResolvedInfiniteOptions

```ts
interface ResolvedInfiniteOptions {
    readonly blockSize: number;
    readonly initialBlocks: number;
    readonly cache: boolean;
    readonly maxBlocks: number;
    readonly threshold: number;
    readonly debounceMs: number;
}
```

Members (6):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `blockSize` | `readonly blockSize: number;` |  |  |
| `initialBlocks` | `readonly initialBlocks: number;` |  |  |
| `cache` | `readonly cache: boolean;` |  |  |
| `maxBlocks` | `readonly maxBlocks: number;` |  |  |
| `threshold` | `readonly threshold: number;` |  |  |
| `debounceMs` | `readonly debounceMs: number;` |  |  |

## Types

### InfiniteScrollCommand

Kind: type

Page: https://salmonui.dev/docs/reference/data-grid/engine-infinite/InfiniteScrollCommand

```ts
type InfiniteScrollCommand = InfiniteScrollLoadedCommand | InfiniteScrollLoadNextCommand | InfiniteScrollRetryCommand | InfiniteScrollReloadCommand;
```

### InfiniteScrollFacade

Kind: type

Page: https://salmonui.dev/docs/reference/data-grid/engine-infinite/InfiniteScrollFacade

```ts
type InfiniteScrollFacade<Row = unknown> = Omit<ModuleFacade<InfiniteScrollModule<Row>>['infiniteScroll'], 'loaded'>;
```

`engine.infiniteScroll`: the generated façade of the
`infiniteScroll` module. Commands `loadNext()`, `retry()`, `reload()`
dispatch `infiniteScroll.loadNext` / `retry` / `reload`; methods
`getStatus()`, `getStats()`, `ensureRange(start, end)`,
`isRowLoaded(index)`. The internal `infiniteScroll.loaded` is left out.

Members (7):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `getStatus` | `getStatus: () => InfiniteScrollState;` | inherited | Load state, exact total (null while unknown) and loaded row count. |
| `getStats` | `getStats: () => InfiniteScrollStats;` | inherited | Request counters (performance gates, demos). |
| `ensureRange` | `ensureRange: (start: number, end: number) => void;` | inherited | Viewport sink: the renderer reports the rendered rows `[start, end)` when its row window changes (never per scroll frame). Schedules loads; does not change the slice until a load settles. |
| `isRowLoaded` | `isRowLoaded: (index: number) => boolean;` | inherited |  |
| `loadNext` | `loadNext: (payload?: PayloadOf<InfiniteScrollLoadNextCommand> \| undefined) => CommandResult;` | inherited |  |
| `reload` | `reload: (payload?: PayloadOf<InfiniteScrollReloadCommand> \| undefined) => CommandResult;` | inherited |  |
| `retry` | `retry: (payload?: PayloadOf<InfiniteScrollRetryCommand> \| undefined) => CommandResult;` | inherited |  |

### InfiniteScrollLoadNextCommand

Kind: type

Page: https://salmonui.dev/docs/reference/data-grid/engine-infinite/InfiniteScrollLoadNextCommand

```ts
type InfiniteScrollLoadNextCommand = {
    type: 'infiniteScroll.loadNext';
};
```

load the block after the last loaded row (no-op when every row is loaded).

Members (1):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `type` | `type: 'infiniteScroll.loadNext';` |  |  |

### InfiniteScrollLoadedCommand

Kind: type

Page: https://salmonui.dev/docs/reference/data-grid/engine-infinite/InfiniteScrollLoadedCommand

```ts
type InfiniteScrollLoadedCommand = {
    type: 'infiniteScroll.loaded';
    version: number;
};
```

A block load settled (dispatched by the module; part of the public command union).

Members (2):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `type` | `type: 'infiniteScroll.loaded';` |  |  |
| `version` | `version: number;` |  |  |

### InfiniteScrollMethods

Kind: type

Page: https://salmonui.dev/docs/reference/data-grid/engine-infinite/InfiniteScrollMethods

```ts
type InfiniteScrollMethods<Row> = {
    getStatus(ctx: ModuleContext<Row>): InfiniteScrollState;
    getStats(ctx: ModuleContext<Row>): InfiniteScrollStats;
    ensureRange(ctx: ModuleContext<Row>, start: number, end: number): void;
    isRowLoaded(ctx: ModuleContext<Row>, index: number): boolean;
};
```

Members (4):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `getStatus` | `getStatus(ctx: ModuleContext<Row>): InfiniteScrollState;` |  | Load state, exact total (null while unknown) and loaded row count. |
| `getStats` | `getStats(ctx: ModuleContext<Row>): InfiniteScrollStats;` |  | Request counters (performance gates, demos). |
| `ensureRange` | `ensureRange(ctx: ModuleContext<Row>, start: number, end: number): void;` |  | Viewport sink: the renderer reports the rendered rows `[start, end)` when its row window changes (never per scroll frame). Schedules loads; does not change the slice until a load settles. |
| `isRowLoaded` | `isRowLoaded(ctx: ModuleContext<Row>, index: number): boolean;` |  |  |

### InfiniteScrollModule

Kind: type

Page: https://salmonui.dev/docs/reference/data-grid/engine-infinite/InfiniteScrollModule

```ts
type InfiniteScrollModule<Row> = DataGridModule<Row, InfiniteScrollState, InfiniteScrollCommand, 'infiniteScroll', InfiniteScrollMethods<Row>>;
```

Members (18):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `name` | `name: "infiniteScroll";` | inherited |  |
| `dependencies` | `dependencies?: readonly string[];` | optional, inherited | Validated at engine creation. |
| `inSnapshot` | `inSnapshot?: boolean;` | optional, inherited | When true (default) the slice lives in `snapshot.modules[name]` and every change replaces the grid snapshot. High-churn modules (focus, selection, drafts) set false and notify through row/cell/header/module channels only. |
| `commands` | `commands: readonly ("infiniteScroll.loadNext" \| "infiniteScroll.loaded" \| "infiniteScroll.reload" \| "infiniteScroll.retry")[];` | inherited | Declared, validated, serializable. Every type must start with `${name}.`. |
| `initialState` | `initialState: (options: DataGridOptions<Row>) => InfiniteScrollState;` | inherited |  |
| `reduce` | `reduce?: ((state: InfiniteScrollState, command: InfiniteScrollCommand, ctx: ModuleContext<Row>) => CommandRejection \| InfiniteScrollState);` | optional, inherited |  |
| `extendColumns` | `extendColumns?: ((columns: readonly CompiledColumn<Row>[], ctx: ModuleContext<Row>) => readonly CompiledColumn<Row>[]);` | optional, inherited |  |
| `extendQuery` | `extendQuery?: ((query: DataQuery, state: InfiniteScrollState) => DataQuery);` | optional, inherited |  |
| `pipeline` | `pipeline?: readonly PipelineStage<Row, InfiniteScrollState>[];` | optional, inherited |  |
| `selectors` | `selectors?: Readonly<Record<string, (snapshot: DataGridSnapshot<Row>) => unknown>>;` | optional, inherited |  |
| `methods` | `methods?: InfiniteScrollMethods<Row>;` | optional, inherited | Reads that need more than the snapshot (facets, pager totals). Must not change state; names may not collide with command actions. |
| `notify` | `notify?: ((previous: InfiniteScrollState, next: InfiniteScrollState, ctx: ModuleContext<Row>) => NotificationScope);` | optional, inherited |  |
| `hiddenColumns` | `hiddenColumns?: ((state: InfiniteScrollState) => readonly string[]);` | optional, inherited | Leaf columns this module hides from the visible column set (grouped columns with `showGroupedColumns: false`). |
| `interceptRead` | `interceptRead?: ((query: DataQuery, state: InfiniteScrollState, ctx: ModuleContext<Row>) => boolean);` | optional, inherited | Remote sources only: return true to serve the main read of `query` yourself (lazy grouping loads group levels instead of rows). The engine then shows no source rows and runs only the stages the source did not perform. |
| `onQueryChange` | `onQueryChange?: ((previous: DataQuery, next: DataQuery, ctx: ModuleContext<Row>) => void);` | optional, inherited | Called after the effective query changed (sort, filter, search, page, group). Runs inside the dispatch of the command that changed it; may dispatch commands through `ctx` (selection clears itself here when it does not persist). |
| `onConnect` | `onConnect?: ((ctx: ModuleContext<Row>) => void);` | optional, inherited | `engine.connect()` ran (`deferDataSource`): start loads that were held while disconnected. |
| `onSourceEvent` | `onSourceEvent?: ((event: DataSourceEvent<Row>, state: InfiniteScrollState, ctx: ModuleContext<Row>) => boolean);` | optional, inherited | A data source event (patch or reset). Return true to consume it: the engine then leaves its source rows unchanged (infinite scroll applies write echoes to the blocks it owns). |
| `dispose` | `dispose?: (() => void);` | optional, inherited |  |

### InfiniteScrollPublicCommand

Kind: type

Page: https://salmonui.dev/docs/reference/data-grid/engine-infinite/InfiniteScrollPublicCommand

```ts
type InfiniteScrollPublicCommand = InfiniteScrollLoadNextCommand | InfiniteScrollRetryCommand | InfiniteScrollReloadCommand;
```

Public `infiniteScroll.*` commands (`engine.dispatch`); `infiniteScroll.loaded` is the module's own.

### InfiniteScrollReloadCommand

Kind: type

Page: https://salmonui.dev/docs/reference/data-grid/engine-infinite/InfiniteScrollReloadCommand

```ts
type InfiniteScrollReloadCommand = {
    type: 'infiniteScroll.reload';
};
```

Drop every block and load the initial blocks again (after changing settings).

Members (1):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `type` | `type: 'infiniteScroll.reload';` |  |  |

### InfiniteScrollRetryCommand

Kind: type

Page: https://salmonui.dev/docs/reference/data-grid/engine-infinite/InfiniteScrollRetryCommand

```ts
type InfiniteScrollRetryCommand = {
    type: 'infiniteScroll.retry';
};
```

Retry after a failed block load.

Members (1):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `type` | `type: 'infiniteScroll.retry';` |  |  |

### InfiniteStatus

Kind: type

Page: https://salmonui.dev/docs/reference/data-grid/engine-infinite/InfiniteStatus

```ts
type InfiniteStatus = 'idle' | 'loading' | 'ready' | 'error';
```

## Constants

### INFINITE_LOADING_ID_PREFIX

Kind: const

Page: https://salmonui.dev/docs/reference/data-grid/engine-infinite/INFINITE_LOADING_ID_PREFIX

```ts
const INFINITE_LOADING_ID_PREFIX = "__loading:";
```

Id prefix of placeholder rows (`kind: 'loading'`): `__loading:<rowIndex>`.

### INFINITE_SCROLL_COMMANDS

Kind: const

Page: https://salmonui.dev/docs/reference/data-grid/engine-infinite/INFINITE_SCROLL_COMMANDS

```ts
const INFINITE_SCROLL_COMMANDS: readonly [
    "infiniteScroll.loaded",
    "infiniteScroll.loadNext",
    "infiniteScroll.retry",
    "infiniteScroll.reload"
];
```

Command types of the `infiniteScroll` module (a renderer that installs the driver lazily declares them up front).
