View as Markdown

API reference: @salmonui/data-grid/engine

DataGridEngineinterface

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

Also exported from @salmonui/data-grid.

interface DataGridEngine<Row> {
    readonly id: string;
    getSnapshot(): DataGridSnapshot<Row>;
    getServerSnapshot(): DataGridSnapshot<Row>;
    subscribe(listener: () => void): () => void;
    select<T>(selector: (snapshot: DataGridSnapshot<Row>) => T): T;
    subscribeSelector<T>(selector: (snapshot: DataGridSnapshot<Row>) => T, listener: (value: T) => void, isEqual?: (a: T, b: T) => boolean): () => void;
    subscribeCell(rowId: RowId, columnId: ColumnId, listener: () => void): () => void;
    subscribeRow(rowId: RowId, listener: () => void): () => void;
    subscribeHeader(columnId: ColumnId, listener: () => void): () => void;
    subscribeModule(name: string, listener: () => void): () => void;
    getCellSnapshot(rowId: RowId, columnId: ColumnId): CellSnapshot | undefined;
    getRowSnapshot(rowId: RowId): RowSnapshot<Row> | undefined;
    getHeaderSnapshot(columnId: ColumnId): HeaderSnapshot | undefined;
    getModuleState<T = unknown>(name: string): T | undefined;
    getSelector(moduleName: string, selectorName: string): ((snapshot: DataGridSnapshot<Row>) => unknown) | undefined;
    getRow(rowId: RowId): Row | undefined;
    getRowIndex(rowId: RowId): number;
    getRowAt(index: number): Row | undefined;
    getRowIdAt(index: number): RowId | undefined;
    getCellValue(rowId: RowId, columnId: ColumnId): unknown;
    getDataSource(): DataSource<Row>;
    setColumns(columns: readonly ColumnDef<Row>[]): void;
    setLocale(next: {
        readonly locale?: string;
        readonly currency?: string;
        readonly timeZone?: string | undefined;
        readonly direction?: 'ltr' | 'rtl';
    }): boolean;
    dispatch(command: DataGridCommand): CommandResult;
    hasCommand(type: string): boolean;
    batch(run: () => void): void;
    onBeforeCommand(listener: (event: BeforeCommandEvent) => boolean | string | void): () => void;
    onCommand(listener: (event: CommandEvent) => void): () => void;
    getCommandLog(): readonly DataGridCommand[];
    getInstrumentation(): DataGridInstrumentation | null;
    connect(): () => void;
    reload(): void;
    refresh(): void;
    readonly disposed: boolean;
    dispose(): void;
}
DataGridEngine members (35)
NameSignatureDescription
idreadonly id: string;
getSnapshotgetSnapshot(): DataGridSnapshot<Row>;
getServerSnapshotgetServerSnapshot(): DataGridSnapshot<Row>;
subscribesubscribe(listener: () => void): () => void;
selectselect<T>(selector: (snapshot: DataGridSnapshot<Row>) => T): T;
subscribeSelectorsubscribeSelector<T>(selector: (snapshot: DataGridSnapshot<Row>) => T, listener: (value: T) => void, isEqual?: (a: T, b: T) => boolean): () => void;
subscribeCellsubscribeCell(rowId: RowId, columnId: ColumnId, listener: () => void): () => void;
subscribeRowsubscribeRow(rowId: RowId, listener: () => void): () => void;
subscribeHeadersubscribeHeader(columnId: ColumnId, listener: () => void): () => void;
subscribeModulesubscribeModule(name: string, listener: () => void): () => void;
getCellSnapshotgetCellSnapshot(rowId: RowId, columnId: ColumnId): CellSnapshot | undefined;
getRowSnapshotgetRowSnapshot(rowId: RowId): RowSnapshot<Row> | undefined;
getHeaderSnapshotgetHeaderSnapshot(columnId: ColumnId): HeaderSnapshot | undefined;
getModuleStategetModuleState<T = unknown>(name: string): T | undefined;
getSelectorgetSelector(moduleName: string, selectorName: string): ((snapshot: DataGridSnapshot<Row>) => unknown) | undefined;
getRowgetRow(rowId: RowId): Row | undefined;

Raw row by id (source rows, including rows filtered out of the view).

getRowIndexgetRowIndex(rowId: RowId): number;

Visible index of a row, or -1.

getRowAtgetRowAt(index: number): Row | undefined;
getRowIdAtgetRowIdAt(index: number): RowId | undefined;
getCellValuegetCellValue(rowId: RowId, columnId: ColumnId): unknown;
getDataSourcegetDataSource(): DataSource<Row>;
setColumnssetColumns(columns: readonly ColumnDef<Row>[]): void;

Recompiles only when the array identity or a definition identity changes.

setLocalesetLocale(next: { readonly locale?: string; readonly currency?: string; readonly timeZone?: string | undefined; readonly direction?: 'ltr' | 'rtl'; }): boolean;

Changes the locale, currency, time zone, or direction at runtime. A format change recompiles the column formatters once and re-runs the pipeline (collation follows the locale); a direction change updates snapshot.direction and the focus module. Omitted fields keep their value (timeZone: undefined given explicitly resets to the runtime zone). Returns false when nothing changed.

dispatchdispatch(command: DataGridCommand): CommandResult;
hasCommandhasCommand(type: string): boolean;

Whether a registered module declares the command type (UI commands probe it before dispatching).

batchbatch(run: () => void): void;
onBeforeCommandonBeforeCommand(listener: (event: BeforeCommandEvent) => boolean | string | void): () => void;
onCommandonCommand(listener: (event: CommandEvent) => void): () => void;
getCommandLoggetCommandLog(): readonly DataGridCommand[];
getInstrumentationgetInstrumentation(): DataGridInstrumentation | null;
connectconnect(): () => void;

With deferDataSource: subscribes to the source and issues the pending read. Returns the disconnect (unsubscribes, aborts the in-flight read, which the next connect() re-issues). A no-op when already connected.

reloadreload(): void;

Re-reads the data source with the current query (retry after a data error). Before connect() the read waits for it.

refreshrefresh(): void;

Refresh: drops the row and cell snapshot caches, invalidates the source cache (DataSource.invalidate), aborts and re-issues the current read, and keeps every module state (sort, filter, group, page, selection, expansion). Rows mutated in place render their new values.

disposedreadonly disposed: boolean;
disposedispose(): void;