# DataGridCoreApi (@salmonui/data-grid)

> The DataGridCoreApi interface of @salmonui/data-grid: 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.

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

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

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

## Reference

Kind: interface

```ts
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.

Members (40):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `engine` | `readonly engine: DataGridEngine<Row>;` |  |  |
| `getColumn` | `getColumn(fieldOrId: string): CompiledColumn<Row> \| undefined;` |  | Leaf column by column id, else the first leaf with that `field`. |
| `getColumns` | `getColumns(): readonly CompiledColumn<Row>[];` |  | Every leaf column in definition order, including hidden ones. |
| `getVisibleColumns` | `getVisibleColumns(): readonly CompiledColumn<Row>[];` |  | Visible leaves in runtime order. |
| `getHiddenColumns` | `getHiddenColumns(): readonly CompiledColumn<Row>[];` |  | Leaves hidden at runtime, in definition order. |
| `getColumnAt` | `getColumnAt(index: number): CompiledColumn<Row> \| undefined;` |  | Visible leaf at an index of `getVisibleColumns()`. |
| `getColumnIndex` | `getColumnIndex(fieldOrId: string): number;` |  | Index of a column in `getVisibleColumns()`, or -1. |
| `showColumns` | `showColumns(fieldsOrIds: string \| readonly string[]): CommandResult;` |  |  |
| `hideColumns` | `hideColumns(fieldsOrIds: string \| readonly string[]): CommandResult;` |  |  |
| `getViewRows` | `getViewRows(): readonly Row[];` |  | Rows of the current view (after the query pipeline), as raw references. |
| `getFilteredRows` | `getFilteredRows(): readonly Row[];` |  | Rows passing search and every filter, in sort order, across every page, as raw references. Without the `filter` module, every row. |
| `getRow` | `getRow(rowId: RowId): Row \| undefined;` |  |  |
| `getRowInfo` | `getRowInfo(rowId: RowId): RowSnapshot<Row> \| undefined;` |  |  |
| `getRowIndex` | `getRowIndex(rowId: RowId): number;` |  | Visible index of a row, or -1. |
| `getRowIdAt` | `getRowIdAt(index: number): RowId \| undefined;` |  | Row id at a visible index (the inverse of `getRowIndex`), or undefined. |
| `getCell` | `getCell(rowId: RowId, field: string): CellSnapshot \| undefined;` |  |  |
| `getDataSource` | `getDataSource(): DataSource<Row>;` |  |  |
| `getPrimaryKeyFields` | `getPrimaryKeyFields(): readonly string[];` |  | `field` of each `primaryKey` leaf column, in column order. |
| `sortColumn` | `sortColumn(field: string, direction: 'asc' \| 'desc', options?: {     readonly multiple?: boolean; }): CommandResult;` |  | `multiple` adds to the current sort (Ctrl+click). Needs the `sort` module. |
| `removeSort` | `removeSort(field: string): CommandResult;` |  |  |
| `clearSorting` | `clearSorting(): CommandResult;` |  |  |
| `filterColumn` | `filterColumn(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. |
| `clearFiltering` | `clearFiltering(fields?: string \| readonly string[]): CommandResult;` |  | Clears every filter, or the filters of the given columns. |
| `removeFilter` | `removeFilter(field: string): CommandResult;` |  |  |
| `getColumnFacet` | `getColumnFacet(field: string, options?: FacetOptions): ColumnFacet \| undefined;` |  | Distinct values with counts for checkbox / Excel filters, or undefined without the `filter` module. |
| `search` | `search(text: string): CommandResult;` |  | Searches with the `search` module settings; empty text clears the search. |
| `clearSearch` | `clearSearch(): CommandResult;` |  |  |
| `goToPage` | `goToPage(page: number): CommandResult;` |  | Needs the `paging` module. |
| `setPageSize` | `setPageSize(pageSize: number): CommandResult;` |  |  |
| `getPageInfo` | `getPageInfo(): PageInfo \| undefined;` |  | Pager model, or undefined without the `paging` module. |
| `groupColumn` | `groupColumn(field: string, index?: number): CommandResult;` |  | Needs the `grouping` module. |
| `ungroupColumn` | `ungroupColumn(field: string): CommandResult;` |  |  |
| `clearGrouping` | `clearGrouping(): CommandResult;` |  |  |
| `toggleGroup` | `toggleGroup(group: GroupTarget, expanded?: boolean): CommandResult;` |  | Toggles (or sets) one group by row id, path key, or path. |
| `expandAllGroups` | `expandAllGroups(): CommandResult;` |  |  |
| `collapseAllGroups` | `collapseAllGroups(): CommandResult;` |  |  |
| `getGroup` | `getGroup(rowId: RowId): GroupRowSnapshot \| undefined;` |  | Caption or footer snapshot of a group row id, or undefined. |
| `getAggregates` | `getAggregates(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). |
| `refresh` | `refresh(): void;` |  | Re-reads the data with the current query and keeps the grid state: `engine.refresh()`. |
| `dispose` | `dispose(): void;` |  |  |
