View as Markdown

API reference: @salmonui/data-grid/engine

DataGridApiinterface

import type { DataGridApi } from '@salmonui/data-grid/engine';
interface DataGridApi<Row> {
    readonly engine: DataGridEngine<Row>;
    getColumn(fieldOrId: string): CompiledColumn<Row> | undefined;
    getColumns(): readonly CompiledColumn<Row>[];
    getVisibleColumns(): readonly CompiledColumn<Row>[];
    getHiddenColumns(): readonly CompiledColumn<Row>[];
    getColumnAt(index: number): CompiledColumn<Row> | undefined;
    getColumnIndex(fieldOrId: string): number;
    showColumns(fieldsOrIds: string | readonly string[]): CommandResult;
    hideColumns(fieldsOrIds: string | readonly string[]): CommandResult;
    getViewRows(): readonly Row[];
    getFilteredRows(): readonly Row[];
    getRow(rowId: RowId): Row | undefined;
    getRowInfo(rowId: RowId): RowSnapshot<Row> | undefined;
    getRowIndex(rowId: RowId): number;
    getRowIdAt(index: number): RowId | undefined;
    getCell(rowId: RowId, field: string): CellSnapshot | undefined;
    getDataSource(): DataSource<Row>;
    getPrimaryKeyFields(): readonly string[];
    sortColumn(field: string, direction: 'asc' | 'desc', options?: {
        readonly multiple?: boolean;
    }): CommandResult;
    removeSort(field: string): CommandResult;
    clearSorting(): CommandResult;
    filterColumn(field: string, operator: string, value: Json, options?: FilterColumnOptions): CommandResult;
    clearFiltering(fields?: string | readonly string[]): CommandResult;
    removeFilter(field: string): CommandResult;
    getColumnFacet(field: string, options?: FacetOptions): ColumnFacet | undefined;
    search(text: string): CommandResult;
    clearSearch(): CommandResult;
    goToPage(page: number): CommandResult;
    setPageSize(pageSize: number): CommandResult;
    getPageInfo(): PageInfo | undefined;
    groupColumn(field: string, index?: number): CommandResult;
    ungroupColumn(field: string): CommandResult;
    clearGrouping(): CommandResult;
    toggleGroup(group: GroupTarget, expanded?: boolean): CommandResult;
    expandAllGroups(): CommandResult;
    collapseAllGroups(): CommandResult;
    getGroup(rowId: RowId): GroupRowSnapshot | undefined;
    getAggregates(groupId?: RowId): AggregateValues | undefined;
    refresh(): void;
    dispose(): void;
}

Imperative DataGrid API over an engine (re-exported by @salmonui/data-grid as DataGridCoreApi and extended there). Every method that takes a column accepts a field or a column id: the column id wins, else the first leaf with that field. Mutating methods dispatch a serializable command and return its CommandResult; read methods return engine-owned frozen values or raw row references.

DataGridApi members (40)
NameSignatureDescription
enginereadonly engine: DataGridEngine<Row>;
getColumngetColumn(fieldOrId: string): CompiledColumn<Row> | undefined;

Leaf column by column id, else the first leaf with that field.

getColumnsgetColumns(): readonly CompiledColumn<Row>[];

Every leaf column in definition order, including hidden ones.

getVisibleColumnsgetVisibleColumns(): readonly CompiledColumn<Row>[];

Visible leaves in runtime order.

getHiddenColumnsgetHiddenColumns(): readonly CompiledColumn<Row>[];

Leaves hidden at runtime, in definition order.

getColumnAtgetColumnAt(index: number): CompiledColumn<Row> | undefined;

Visible leaf at an index of getVisibleColumns().

getColumnIndexgetColumnIndex(fieldOrId: string): number;

Index of a column in getVisibleColumns(), or -1.

showColumnsshowColumns(fieldsOrIds: string | readonly string[]): CommandResult;
hideColumnshideColumns(fieldsOrIds: string | readonly string[]): CommandResult;
getViewRowsgetViewRows(): readonly Row[];

Rows of the current view (after the query pipeline), as raw references.

getFilteredRowsgetFilteredRows(): readonly Row[];

Rows passing search and every filter, in sort order, across every page, as raw references. Without the filter module, every row.

getRowgetRow(rowId: RowId): Row | undefined;
getRowInfogetRowInfo(rowId: RowId): RowSnapshot<Row> | undefined;
getRowIndexgetRowIndex(rowId: RowId): number;

Visible index of a row, or -1.

getRowIdAtgetRowIdAt(index: number): RowId | undefined;

Row id at a visible index (the inverse of getRowIndex), or undefined.

getCellgetCell(rowId: RowId, field: string): CellSnapshot | undefined;
getDataSourcegetDataSource(): DataSource<Row>;
getPrimaryKeyFieldsgetPrimaryKeyFields(): readonly string[];

field of each primaryKey leaf column, in column order.

sortColumnsortColumn(field: string, direction: 'asc' | 'desc', options?: { readonly multiple?: boolean; }): CommandResult;

multiple adds to the current sort (Ctrl+click). Needs the sort module.

removeSortremoveSort(field: string): CommandResult;
clearSortingclearSorting(): CommandResult;
filterColumnfilterColumn(field: string, operator: string, value: Json, options?: FilterColumnOptions): CommandResult;

An array value with a scalar operator ORs one condition per value. Needs the filter module.

clearFilteringclearFiltering(fields?: string | readonly string[]): CommandResult;

Clears every filter, or the filters of the given columns.

removeFilterremoveFilter(field: string): CommandResult;
getColumnFacetgetColumnFacet(field: string, options?: FacetOptions): ColumnFacet | undefined;

Distinct values with counts for checkbox / Excel filters, or undefined without the filter module.

searchsearch(text: string): CommandResult;

Searches with the search module settings; empty text clears the search.

clearSearchclearSearch(): CommandResult;
goToPagegoToPage(page: number): CommandResult;

Needs the paging module.

setPageSizesetPageSize(pageSize: number): CommandResult;
getPageInfogetPageInfo(): PageInfo | undefined;

Pager model, or undefined without the paging module.

groupColumngroupColumn(field: string, index?: number): CommandResult;

Needs the grouping module.

ungroupColumnungroupColumn(field: string): CommandResult;
clearGroupingclearGrouping(): CommandResult;
toggleGrouptoggleGroup(group: GroupTarget, expanded?: boolean): CommandResult;

Toggles (or sets) one group by row id, path key, or path.

expandAllGroupsexpandAllGroups(): CommandResult;
collapseAllGroupscollapseAllGroups(): CommandResult;
getGroupgetGroup(rowId: RowId): GroupRowSnapshot | undefined;

Caption or footer snapshot of a group row id, or undefined.

getAggregatesgetAggregates(groupId?: RowId): AggregateValues | undefined;

Without an argument the footer aggregates (undefined without the aggregates module); with a group row id that group's aggregates (undefined for an unknown id).

refreshrefresh(): void;

Re-reads the data with the current query and keeps the grid state: engine.refresh().

disposedispose(): void;