# DataGridModule (@salmonui/data-grid/engine)

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

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

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

Also exported from `@salmonui/data-grid`.

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

## Reference

Kind: interface

```ts
interface DataGridModule<Row = unknown, State = unknown, Command extends DataGridCommand = DataGridCommand, Name extends string = string, Methods extends ModuleMethods<Row> = {}> {
    readonly name: Name;
    readonly dependencies?: readonly string[];
    readonly inSnapshot?: boolean;
    readonly commands: readonly Command['type'][];
    initialState(options: DataGridOptions<Row>): State;
    reduce?(state: State, command: Command, ctx: ModuleContext<Row>): State | CommandRejection;
    extendColumns?(columns: readonly CompiledColumn<Row>[], ctx: ModuleContext<Row>): readonly CompiledColumn<Row>[];
    extendQuery?(query: DataQuery, state: State): DataQuery;
    readonly pipeline?: readonly PipelineStage<Row, State>[];
    readonly selectors?: Readonly<Record<string, (snapshot: DataGridSnapshot<Row>) => unknown>>;
    readonly methods?: Methods;
    notify?(previous: State, next: State, ctx: ModuleContext<Row>): NotificationScope;
    hiddenColumns?(state: State): readonly ColumnId[];
    interceptRead?(query: DataQuery, state: State, ctx: ModuleContext<Row>): boolean;
    onQueryChange?(previous: DataQuery, next: DataQuery, ctx: ModuleContext<Row>): void;
    onConnect?(ctx: ModuleContext<Row>): void;
    onSourceEvent?(event: DataSourceEvent<Row>, state: State, ctx: ModuleContext<Row>): boolean;
    dispose?(): void;
}
```

Members (18):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `name` | `readonly name: Name;` |  |  |
| `dependencies` | `readonly dependencies?: readonly string[];` | optional | Validated at engine creation. |
| `inSnapshot` | `readonly inSnapshot?: boolean;` | optional | 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` | `readonly commands: readonly Command['type'][];` |  | Declared, validated, serializable. Every type must start with `${name}.`. |
| `initialState` | `initialState(options: DataGridOptions<Row>): State;` |  |  |
| `reduce` | `reduce?(state: State, command: Command, ctx: ModuleContext<Row>): State \| CommandRejection;` | optional |  |
| `extendColumns` | `extendColumns?(columns: readonly CompiledColumn<Row>[], ctx: ModuleContext<Row>): readonly CompiledColumn<Row>[];` | optional |  |
| `extendQuery` | `extendQuery?(query: DataQuery, state: State): DataQuery;` | optional |  |
| `pipeline` | `readonly pipeline?: readonly PipelineStage<Row, State>[];` | optional |  |
| `selectors` | `readonly selectors?: Readonly<Record<string, (snapshot: DataGridSnapshot<Row>) => unknown>>;` | optional |  |
| `methods` | `readonly methods?: Methods;` | optional | Reads that need more than the snapshot (facets, pager totals). Must not change state; names may not collide with command actions. |
| `notify` | `notify?(previous: State, next: State, ctx: ModuleContext<Row>): NotificationScope;` | optional |  |
| `hiddenColumns` | `hiddenColumns?(state: State): readonly ColumnId[];` | optional | Leaf columns this module hides from the visible column set (grouped columns with `showGroupedColumns: false`). |
| `interceptRead` | `interceptRead?(query: DataQuery, state: State, ctx: ModuleContext<Row>): boolean;` | optional | 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 | 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 | `engine.connect()` ran (`deferDataSource`): start loads that were held while disconnected. |
| `onSourceEvent` | `onSourceEvent?(event: DataSourceEvent<Row>, state: State, ctx: ModuleContext<Row>): boolean;` | optional | 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 |  |
