View as Markdown

API reference: @salmonui/data-grid/engine

DataGridModuleinterface

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

Also exported from @salmonui/data-grid.

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;
}
DataGridModule members (18)
NameSignatureDescription
namereadonly name: Name;
dependenciesoptionalreadonly dependencies?: readonly string[];

Validated at engine creation.

inSnapshotoptionalreadonly inSnapshot?: boolean;

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.

commandsreadonly commands: readonly Command['type'][];

Declared, validated, serializable. Every type must start with ${name}..

initialStateinitialState(options: DataGridOptions<Row>): State;
reduceoptionalreduce?(state: State, command: Command, ctx: ModuleContext<Row>): State | CommandRejection;
extendColumnsoptionalextendColumns?(columns: readonly CompiledColumn<Row>[], ctx: ModuleContext<Row>): readonly CompiledColumn<Row>[];
extendQueryoptionalextendQuery?(query: DataQuery, state: State): DataQuery;
pipelineoptionalreadonly pipeline?: readonly PipelineStage<Row, State>[];
selectorsoptionalreadonly selectors?: Readonly<Record<string, (snapshot: DataGridSnapshot<Row>) => unknown>>;
methodsoptionalreadonly methods?: Methods;

Reads that need more than the snapshot (facets, pager totals). Must not change state; names may not collide with command actions.

notifyoptionalnotify?(previous: State, next: State, ctx: ModuleContext<Row>): NotificationScope;
hiddenColumnsoptionalhiddenColumns?(state: State): readonly ColumnId[];

Leaf columns this module hides from the visible column set (grouped columns with showGroupedColumns: false).

interceptReadoptionalinterceptRead?(query: DataQuery, state: State, ctx: ModuleContext<Row>): boolean;

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.

onQueryChangeoptionalonQueryChange?(previous: DataQuery, next: DataQuery, ctx: ModuleContext<Row>): void;

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).

onConnectoptionalonConnect?(ctx: ModuleContext<Row>): void;

engine.connect() ran (deferDataSource): start loads that were held while disconnected.

onSourceEventoptionalonSourceEvent?(event: DataSourceEvent<Row>, state: State, ctx: ModuleContext<Row>): boolean;

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).

disposeoptionaldispose?(): void;