# Grid API reference

> Every GridApi method grouped by task, with links to the generated reference for full signatures and types.

`createGrid(container, options)` returns a `GridApi<TRow>`. This page groups its methods by task. Each name links to the generated reference, built from the TypeScript source of `@birchui/core`, which lists exact signatures and every related type. The full package reference is at [@birchui/core](https://docs.birchui.com/api/core.md).

```ts
import { createGrid, type GridApi } from '@birchui/core';

const grid: GridApi<Order> = createGrid<Order>(document.querySelector('#orders')!, { columns, rows: orders });
```

The API is a single object per grid. Its methods are own properties that do not depend on `this`, so you can destructure them or pass them as callbacks (`const { setQuickFilter } = grid`). It reports itself as `[object BirchGridApi]` through `Object.prototype.toString`, which helps when inspecting it in logs and dev tools. Do not use it after `destroy()`; drop your reference instead.

## Lifecycle and options

| Method | Description |
| --- | --- |
| [`element`](https://docs.birchui.com/api/core.md#gridapi-element) | The grid's root element (`.lq-grid`). |
| [`update(partial)`](https://docs.birchui.com/api/core.md#gridapi-update) | Apply changed options without recreating the grid. See [Updating data](https://docs.birchui.com/grid/updating-data.md#changing-options-update). |
| [`getOptions()`](https://docs.birchui.com/api/core.md#gridapi-getoptions) | The current options. |
| [`on(event, listener)`](https://docs.birchui.com/api/core.md#gridapi-on) | Subscribe to an event; returns an unsubscribe function. See [Events](https://docs.birchui.com/grid/events.md). |
| [`destroy()`](https://docs.birchui.com/api/core.md#gridapi-destroy) | Remove the grid, its listeners and its modules. |
| [`hasModule(name)`](https://docs.birchui.com/api/core.md#gridapi-hasmodule) | Whether a module is installed. See [Modules](https://docs.birchui.com/grid/modules.md). |

## Rows

| Method | Description |
| --- | --- |
| [`setRows(rows)`](https://docs.birchui.com/api/core.md#gridapi-setrows) | Replace all rows. |
| [`getRows()`](https://docs.birchui.com/api/core.md#gridapi-getrows) | The source rows, in the order they were given. |
| [`applyTransaction(tx)`](https://docs.birchui.com/api/core.md#gridapi-applytransaction) | Add, update and remove rows in one pass. |
| [`getRowId(row)`](https://docs.birchui.com/api/core.md#gridapi-getrowid) | The ID of a row. |
| [`getRowById(id)`](https://docs.birchui.com/api/core.md#gridapi-getrowbyid) | The row with an ID. |
| [`getDisplayRows()`](https://docs.birchui.com/api/core.md#gridapi-getdisplayrows) | The rows of the current page, after filtering, sorting and module stages. |
| [`getAllDisplayRows()`](https://docs.birchui.com/api/core.md#gridapi-getalldisplayrows) | The same rows across every page; identical to `getDisplayRows()` without pagination. |
| [`getDisplayRow(rowIndex)`](https://docs.birchui.com/api/core.md#gridapi-getdisplayrow) | One display row by index. |
| [`getRenderedRows()`](https://docs.birchui.com/api/core.md#gridapi-getrenderedrows) | The display rows that currently have DOM elements. |
| [`refresh()`](https://docs.birchui.com/api/core.md#gridapi-refresh) | Re-run the row pipeline after in-place changes. |
| [`redraw()`](https://docs.birchui.com/api/core.md#gridapi-redraw) | Re-render visible cells without re-running the pipeline. |

## Values

| Method | Description |
| --- | --- |
| [`getValue(row, colId)`](https://docs.birchui.com/api/core.md#gridapi-getvalue) | A cell's value, from a source row or a display row. |
| [`getFormattedValue(row, colId)`](https://docs.birchui.com/api/core.md#gridapi-getformattedvalue) | A cell's display text. |
| [`setValue(row, colId, value, source?)`](https://docs.birchui.com/api/core.md#gridapi-setvalue) | Write a value through the column; returns whether it changed. |

## Columns

| Method | Description |
| --- | --- |
| [`setColumns(columns)`](https://docs.birchui.com/api/core.md#gridapi-setcolumns) | Replace the column definitions, keeping user layout for surviving IDs. |
| [`getColumns()`](https://docs.birchui.com/api/core.md#gridapi-getcolumns) | All resolved columns, including hidden ones. |
| [`getDisplayColumns()`](https://docs.birchui.com/api/core.md#gridapi-getdisplaycolumns) | Visible columns in display order. |
| [`getColumn(colId)`](https://docs.birchui.com/api/core.md#gridapi-getcolumn) | One resolved column. |
| [`setColumnWidth(colId, width)`](https://docs.birchui.com/api/core.md#gridapi-setcolumnwidth) | Resize a column. |
| [`autosizeColumn(colId)`](https://docs.birchui.com/api/core.md#gridapi-autosizecolumn) | Fit one column to its content. |
| [`autosizeColumns()`](https://docs.birchui.com/api/core.md#gridapi-autosizecolumns) | Fit every visible, resizable column. |
| [`moveColumn(colId, toIndex)`](https://docs.birchui.com/api/core.md#gridapi-movecolumn) | Move a column. |
| [`setColumnPinned(colId, pinned)`](https://docs.birchui.com/api/core.md#gridapi-setcolumnpinned) | Pin left, right or unpin. |
| [`setColumnHidden(colId, hidden)`](https://docs.birchui.com/api/core.md#gridapi-setcolumnhidden) | Hide or show a column. |
| [`getColumnState()`](https://docs.birchui.com/api/core.md#gridapi-getcolumnstate) | Widths, pinning, visibility and order of every column. |
| [`applyColumnState(state)`](https://docs.birchui.com/api/core.md#gridapi-applycolumnstate) | Restore a saved layout. |

See [Columns](https://docs.birchui.com/grid/columns.md) and [Column operations](https://docs.birchui.com/grid/column-operations.md).

## Sorting and filtering

| Method | Description |
| --- | --- |
| [`setSort(sort)`](https://docs.birchui.com/api/core.md#gridapi-setsort) | Replace the sort model. |
| [`getSort()`](https://docs.birchui.com/api/core.md#gridapi-getsort) | The current sort model. |
| [`setFilter(colId, model)`](https://docs.birchui.com/api/core.md#gridapi-setfilter) | Set or clear (`null`) one column filter. |
| [`getFilterModel()`](https://docs.birchui.com/api/core.md#gridapi-getfiltermodel) | All column filters. |
| [`setFilterModel(model)`](https://docs.birchui.com/api/core.md#gridapi-setfiltermodel) | Replace all column filters. |
| [`setQuickFilter(text)`](https://docs.birchui.com/api/core.md#gridapi-setquickfilter) | Search every visible column. |

See [Sorting](https://docs.birchui.com/grid/sorting.md) and [Filtering](https://docs.birchui.com/grid/filtering.md).

## Selection

| Method | Description |
| --- | --- |
| [`getSelectedRows()`](https://docs.birchui.com/api/core.md#gridapi-getselectedrows) | The selected row objects. |
| [`getSelectedIds()`](https://docs.birchui.com/api/core.md#gridapi-getselectedids) | The selected row IDs. |
| [`setRowSelected(id, selected)`](https://docs.birchui.com/api/core.md#gridapi-setrowselected) | Select or deselect one row. |
| [`selectAll()`](https://docs.birchui.com/api/core.md#gridapi-selectall) | Select every row that passes the filters. |
| [`deselectAll()`](https://docs.birchui.com/api/core.md#gridapi-deselectall) | Clear the selection. |

See [Selection](https://docs.birchui.com/grid/selection.md).

## Focus, scrolling and editing

| Method | Description |
| --- | --- |
| [`focusCell(rowIndex, colId)`](https://docs.birchui.com/api/core.md#gridapi-focuscell) | Focus and scroll to a cell. |
| [`getFocusedCell()`](https://docs.birchui.com/api/core.md#gridapi-getfocusedcell) | The focused cell, or `null`. |
| [`scrollToRow(rowIndex, align?)`](https://docs.birchui.com/api/core.md#gridapi-scrolltorow) | Scroll a row into view (`auto`, `start`, `center` or `end`). |
| [`scrollToColumn(colId)`](https://docs.birchui.com/api/core.md#gridapi-scrolltocolumn) | Scroll an unpinned column into view. |
| [`startEdit(rowIndex, colId, initialInput?)`](https://docs.birchui.com/api/core.md#gridapi-startedit) | Open the editor; returns `false` when the cell is not editable. |
| [`stopEdit(cancel?)`](https://docs.birchui.com/api/core.md#gridapi-stopedit) | Commit, or cancel with `true`. |
| [`isEditing()`](https://docs.birchui.com/api/core.md#gridapi-isediting) | Whether an editor is open. |

See [Keyboard navigation & accessibility](https://docs.birchui.com/grid/accessibility.md) and [Editing](https://docs.birchui.com/grid/editing.md).

## Expansion

| Method | Description |
| --- | --- |
| [`setExpanded(rowIds, expanded)`](https://docs.birchui.com/api/core.md#gridapi-setexpanded) | Expand or collapse one row ID or an array of IDs, with a single re-render. |
| [`isExpanded(rowId, options?)`](https://docs.birchui.com/api/core.md#gridapi-isexpanded) | The row's expansion state. Rows without an explicit state follow `expandAll()` / `collapseAll()`; pass `{ ignoreExpandAll: true }` to get only explicit state (`undefined` otherwise). |
| [`expandAll()`](https://docs.birchui.com/api/core.md#gridapi-expandall) | Expand every expandable row. |
| [`collapseAll()`](https://docs.birchui.com/api/core.md#gridapi-collapseall) | Collapse every expandable row. |

```ts
const topLevelGroups = grid
  .getAllDisplayRows()
  .filter((row) => row.kind === 'group' && row.depth === 0)
  .map((row) => row.id);

grid.setExpanded(topLevelGroups, true);
const explicit = grid.isExpanded(topLevelGroups[0], { ignoreExpandAll: true });
```

Row IDs of group and tree rows are generated by Grid Pro; read them from the display rows as above rather than building them by hand.

Expandable rows come from Grid Pro: see [Row grouping](https://docs.birchui.com/grid-pro/row-grouping.md), [Tree data](https://docs.birchui.com/grid-pro/tree-data.md) and [Master/detail](https://docs.birchui.com/grid-pro/master-detail.md).

## Pagination and export

| Method | Description |
| --- | --- |
| [`setPage(page)`](https://docs.birchui.com/api/core.md#gridapi-setpage) | Go to a zero-based page, clamped to the valid range. |
| [`getPage()`](https://docs.birchui.com/api/core.md#gridapi-getpage) | The current page. |
| [`getPageCount()`](https://docs.birchui.com/api/core.md#gridapi-getpagecount) | The number of pages. |
| [`exportCsv(options?)`](https://docs.birchui.com/api/core.md#gridapi-exportcsv) | The current view as a CSV string. |
| [`downloadCsv(options?)`](https://docs.birchui.com/api/core.md#gridapi-downloadcsv) | Save the current view as a CSV file. |

See [Pagination](https://docs.birchui.com/grid/pagination.md) and [CSV export](https://docs.birchui.com/grid/csv-export.md).

## Methods added by Grid Pro

> **Grid Pro: Paid feature. Fully functional without a key; a license removes the watermark. Pricing: https://docs.birchui.com/getting-started/pricing.md**
>
> Installing Grid Pro modules adds methods to the same API object, such as `exportExcel()` and `importExcel()` from `ExcelModule`. They are optional members of `GridApi`, so call them with optional chaining, `grid.exportExcel?.({ fileName: 'orders.xlsx' })`, in code that may run without the module. See [Excel export & import](https://docs.birchui.com/grid-pro/excel-export.md) and the [@birchui/grid-pro reference](https://docs.birchui.com/api/grid-pro.md).

## Full interface

**`GridApi`** (interface from `@birchui/core`, full reference: https://docs.birchui.com/api/core.md)

```ts
interface GridApi<TRow = RowData> extends Widget<GridOptions<TRow>, GridEvents<TRow>>, GridFeatureApi<TRow>
```

| Property | Type | Description |
| --- | --- | --- |
| `getOptions` | `() => Readonly<GridOptions<TRow>>` |  |
| `translate` | `(key: string, fallback: string, params?: Record<string, string \| number>) => string` |  |
| `getDirection` | `() => 'ltr' \| 'rtl'` |  |
| `setRows` | `(rows: TRow[]) => void` |  |
| `getRows` | `() => readonly TRow[]` |  |
| `applyTransaction` | `(tx: RowTransaction<TRow>) => void` |  |
| `getRowId` | `(row: TRow) => string` |  |
| `getRowById` | `(id: string) => TRow \| undefined` |  |
| `setColumns` | `(columns: (ColumnDef<TRow> \| ColumnGroupDef<TRow>)[]) => void` |  |
| `getColumns` | `() => readonly ResolvedColumn<TRow>[]` |  |
| `getColumnGroups` | `() => readonly ResolvedColumnGroup<TRow>[]` |  |
| `setColumnGroupOpen` | `(groupId: string, open: boolean) => void` |  |
| `getDisplayColumns` | `() => readonly ResolvedColumn<TRow>[]` |  |
| `getColumn` | `(colId: string) => ResolvedColumn<TRow> \| undefined` |  |
| `getColumnState` | `() => ColumnState[]` |  |
| `applyColumnState` | `(state: ColumnState[]) => void` |  |
| `setColumnWidth` | `(colId: string, width: number) => void` |  |
| `autosizeColumn` | `(colId: string) => void` |  |
| `autosizeColumns` | `() => void` |  |
| `moveColumn` | `(colId: string, toIndex: number) => void` |  |
| `setColumnPinned` | `(colId: string, pinned: 'left' \| 'right' \| null) => void` |  |
| `setColumnHidden` | `(colId: string, hidden: boolean) => void` |  |
| `setSort` | `(sort: SortItem[]) => void` |  |
| `getSort` | `() => SortItem[]` |  |
| `setFilter` | `(colId: string, model: FilterModel \| null) => void` |  |
| `getFilterModel` | `() => Record<string, FilterModel>` |  |
| `setFilterModel` | `(model: Record<string, FilterModel>) => void` |  |
| `setQuickFilter` | `(text: string) => void` |  |
| `getDisplayRows` | `() => readonly DisplayRow<TRow>[]` |  |
| `getAllDisplayRows` | `() => readonly DisplayRow<TRow>[]` |  |
| `getRenderedRows` | `() => readonly DisplayRow<TRow>[]` |  |
| `getDisplayRow` | `(rowIndex: number) => DisplayRow<TRow> \| undefined` |  |
| `getValue` | `(row: TRow \| DisplayRow<TRow>, colId: string) => unknown` |  |
| `getFormattedValue` | `(row: TRow \| DisplayRow<TRow>, colId: string) => string` |  |
| `setValue` | `(row: TRow, colId: string, value: unknown, source?: CellValueChangedEvent['source']) => boolean` |  |
| `refresh` | `() => void` |  |
| `redraw` | `() => void` |  |
| `scrollToRow` | `(rowIndex: number, align?: 'auto' \| 'start' \| 'center' \| 'end') => void` |  |
| `scrollToColumn` | `(colId: string) => void` |  |
| `getSelectedRows` | `() => TRow[]` |  |
| `getSelectedIds` | `() => string[]` |  |
| `setRowSelected` | `(id: string, selected: boolean) => void` |  |
| `selectAll` | `() => void` |  |
| `deselectAll` | `() => void` |  |
| `focusCell` | `(rowIndex: number, colId: string) => void` |  |
| `getFocusedCell` | `() => CellPosition \| null` |  |
| `startEdit` | `(rowIndex: number, colId: string, initialInput?: string) => boolean` |  |
| `stopEdit` | `(cancel?: boolean) => void` |  |
| `isEditing` | `() => boolean` |  |
| `setExpanded` | `(rowIds: string \| readonly string[], expanded: boolean) => void` |  |
| `isExpanded` | `(rowId: string, options?: ExpansionQuery) => boolean \| undefined` |  |
| `expandAll` | `() => void` |  |
| `collapseAll` | `() => void` |  |
| `setPage` | `(page: number) => void` |  |
| `getPage` | `() => number` |  |
| `getPageCount` | `() => number` |  |
| `exportCsv` | `(options?: CsvExportOptions) => string` |  |
| `downloadCsv` | `(options?: CsvExportOptions) => void` |  |
| `hasModule` | `(name: string) => boolean` |  |
| `undo` | `() => boolean` |  |
| `redo` | `() => boolean` |  |
| `canUndo` | `() => boolean` |  |
| `canRedo` | `() => boolean` |  |
| `clearHistory` | `() => void` |  |
| `getState` | `() => GridState` |  |
| `setState` | `(state: Partial<GridState>) => void` |  |
| `setGroupBy?` | `(colIds: ((keyof TRow & string) \| (string & {}))[] \| null) => void` | Added by @birchui/grid-pro when its module is installed. |
| `getGroupBy?` | `() => string[]` | Added by @birchui/grid-pro when its module is installed. |
| `expandToLevel?` | `(level: number) => void` | Added by @birchui/grid-pro when its module is installed. |
| `setPivot?` | `(options: PivotOptions \| null) => void` | Added by @birchui/grid-pro when its module is installed. |
| `getPivot?` | `() => PivotOptions \| null` | Added by @birchui/grid-pro when its module is installed. |
| `getPivotResult?` | `() => PivotMatrix \| null` | Added by @birchui/grid-pro when its module is installed. |
| `getColumnAggregate?` | `(colId: string, aggFunc?: AggFuncInput) => unknown` | Added by @birchui/grid-pro when its module is installed. |
| `getCellRanges?` | `() => CellRange[]` | Added by @birchui/grid-pro when its module is installed. |
| `setCellRange?` | `(range: CellRange \| null) => void` | Added by @birchui/grid-pro when its module is installed. |
| `addCellRange?` | `(range: CellRange) => void` | Added by @birchui/grid-pro when its module is installed. |
| `clearCellRanges?` | `() => void` | Added by @birchui/grid-pro when its module is installed. |
| `getRangeValues?` | `(rangeIndex?: number) => unknown[][]` | Added by @birchui/grid-pro when its module is installed. |
| `onRangeChanged?` | `(listener: (event: RangeChangedEvent) => void) => () => void` | Added by @birchui/grid-pro when its module is installed. |
| `copyToClipboard?` | `() => Promise<void>` | Added by @birchui/grid-pro when its module is installed. |
| `cutToClipboard?` | `() => Promise<void>` | Added by @birchui/grid-pro when its module is installed. |
| `pasteFromClipboard?` | `() => Promise<number>` | Added by @birchui/grid-pro when its module is installed. |
| `pasteText?` | `(text: string) => number` | Added by @birchui/grid-pro when its module is installed. |
| `setDetailExpanded?` | `(rowId: string, expanded: boolean) => void` | Added by @birchui/grid-pro when its module is installed. |
| `isDetailExpanded?` | `(rowId: string) => boolean` | Added by @birchui/grid-pro when its module is installed. |
| `buildExcelWorkbook?` | `(options?: ExcelExportOptions) => XlsxWorkbook` | Added by @birchui/grid-pro when its module is installed. |
| `exportExcel?` | `(options?: ExcelExportOptions) => Promise<void>` | Added by @birchui/grid-pro when its module is installed. |
| `getExcelBlob?` | `(options?: ExcelExportOptions) => Promise<Blob>` | Added by @birchui/grid-pro when its module is installed. |
| `importExcel?` | `(data: Blob \| ArrayBuffer \| Uint8Array, options?: ExcelImportOptions) => Promise<ExcelImportResult<TRow>>` | Added by @birchui/grid-pro when its module is installed. |
| `getToolPanelColumns?` | `() => ResolvedColumn<TRow>[]` | Added by @birchui/grid-pro when its module is installed. |
| `openToolPanel?` | `(id: ToolPanelId) => void` | Added by @birchui/grid-pro when its module is installed. |
| `closeToolPanel?` | `() => void` | Added by @birchui/grid-pro when its module is installed. |
| `getOpenedToolPanel?` | `() => ToolPanelId \| null` | Added by @birchui/grid-pro when its module is installed. |
| `setSideBarVisible?` | `(visible: boolean) => void` | Added by @birchui/grid-pro when its module is installed. |
| `isSideBarVisible?` | `() => boolean` | Added by @birchui/grid-pro when its module is installed. |
| `createRangeChart?` | `(params?: CreateRangeChartParams<TRow>) => RangeChartRef \| null` | Added by @birchui/grid-pro when its module is installed. |
| `getChartRefs?` | `() => RangeChartRef[]` | Added by @birchui/grid-pro when its module is installed. |
| `readonly element` | `HTMLElement` | Inherited from Widget. |
| `update` | `(options: Partial<GridOptions<TRow>>) => void` | Inherited from Widget. |
| `on` | `<K extends keyof TEvents & string>(event: K, listener: Listener<TEvents[K]>) => () => void` | Inherited from Widget. |
| `destroy` | `() => void` | Inherited from Widget. |
| `moveRow` | `(row: string \| TRow, toIndex: number) => boolean` | Inherited from GridFeatureApi. |
| `getPinnedTopRows` | `() => readonly TRow[]` | Inherited from GridFeatureApi. |
| `getPinnedBottomRows` | `() => readonly TRow[]` | Inherited from GridFeatureApi. |
| `flashCells` | `(params?: FlashCellsParams<TRow> \| undefined) => void` | Inherited from GridFeatureApi. |
| `find` | `(text: string, options?: FindOptions) => FindMatch<TRow>[]` | Inherited from GridFeatureApi. |
| `findNext` | `() => FindMatch<TRow> \| null` | Inherited from GridFeatureApi. |
| `findPrevious` | `() => FindMatch<TRow> \| null` | Inherited from GridFeatureApi. |
| `getFindMatches` | `() => FindMatch<TRow>[]` | Inherited from GridFeatureApi. |
| `getActiveFindMatch` | `() => FindMatch<TRow> \| null` | Inherited from GridFeatureApi. |
| `clearFind` | `() => void` | Inherited from GridFeatureApi. |
| `openFindBar` | `() => void` | Inherited from GridFeatureApi. |
| `closeFindBar` | `() => void` | Inherited from GridFeatureApi. |
| `print` | `() => void` | Inherited from GridFeatureApi. |
