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.
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 |
The grid's root element (.lq-grid). |
update(partial) |
Apply changed options without recreating the grid. See Updating data. |
getOptions() |
The current options. |
on(event, listener) |
Subscribe to an event; returns an unsubscribe function. See Events. |
destroy() |
Remove the grid, its listeners and its modules. |
hasModule(name) |
Whether a module is installed. See Modules. |
Rows#
| Method | Description |
|---|---|
setRows(rows) |
Replace all rows. |
getRows() |
The source rows, in the order they were given. |
applyTransaction(tx) |
Add, update and remove rows in one pass. |
getRowId(row) |
The ID of a row. |
getRowById(id) |
The row with an ID. |
getDisplayRows() |
The rows of the current page, after filtering, sorting and module stages. |
getAllDisplayRows() |
The same rows across every page; identical to getDisplayRows() without pagination. |
getDisplayRow(rowIndex) |
One display row by index. |
getRenderedRows() |
The display rows that currently have DOM elements. |
refresh() |
Re-run the row pipeline after in-place changes. |
redraw() |
Re-render visible cells without re-running the pipeline. |
Values#
| Method | Description |
|---|---|
getValue(row, colId) |
A cell's value, from a source row or a display row. |
getFormattedValue(row, colId) |
A cell's display text. |
setValue(row, colId, value, source?) |
Write a value through the column; returns whether it changed. |
Columns#
| Method | Description |
|---|---|
setColumns(columns) |
Replace the column definitions, keeping user layout for surviving IDs. |
getColumns() |
All resolved columns, including hidden ones. |
getDisplayColumns() |
Visible columns in display order. |
getColumn(colId) |
One resolved column. |
setColumnWidth(colId, width) |
Resize a column. |
autosizeColumn(colId) |
Fit one column to its content. |
autosizeColumns() |
Fit every visible, resizable column. |
moveColumn(colId, toIndex) |
Move a column. |
setColumnPinned(colId, pinned) |
Pin left, right or unpin. |
setColumnHidden(colId, hidden) |
Hide or show a column. |
getColumnState() |
Widths, pinning, visibility and order of every column. |
applyColumnState(state) |
Restore a saved layout. |
See Columns and Column operations.
Sorting and filtering#
| Method | Description |
|---|---|
setSort(sort) |
Replace the sort model. |
getSort() |
The current sort model. |
setFilter(colId, model) |
Set or clear (null) one column filter. |
getFilterModel() |
All column filters. |
setFilterModel(model) |
Replace all column filters. |
setQuickFilter(text) |
Search every visible column. |
Selection#
| Method | Description |
|---|---|
getSelectedRows() |
The selected row objects. |
getSelectedIds() |
The selected row IDs. |
setRowSelected(id, selected) |
Select or deselect one row. |
selectAll() |
Select every row that passes the filters. |
deselectAll() |
Clear the selection. |
See Selection.
Focus, scrolling and editing#
| Method | Description |
|---|---|
focusCell(rowIndex, colId) |
Focus and scroll to a cell. |
getFocusedCell() |
The focused cell, or null. |
scrollToRow(rowIndex, align?) |
Scroll a row into view (auto, start, center or end). |
scrollToColumn(colId) |
Scroll an unpinned column into view. |
startEdit(rowIndex, colId, initialInput?) |
Open the editor; returns false when the cell is not editable. |
stopEdit(cancel?) |
Commit, or cancel with true. |
isEditing() |
Whether an editor is open. |
See Keyboard navigation & accessibility and Editing.
Expansion#
| Method | Description |
|---|---|
setExpanded(rowIds, expanded) |
Expand or collapse one row ID or an array of IDs, with a single re-render. |
isExpanded(rowId, options?) |
The row's expansion state. Rows without an explicit state follow expandAll() / collapseAll(); pass { ignoreExpandAll: true } to get only explicit state (undefined otherwise). |
expandAll() |
Expand every expandable row. |
collapseAll() |
Collapse every expandable row. |
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, Tree data and Master/detail.
Pagination and export#
| Method | Description |
|---|---|
setPage(page) |
Go to a zero-based page, clamped to the valid range. |
getPage() |
The current page. |
getPageCount() |
The number of pages. |
exportCsv(options?) |
The current view as a CSV string. |
downloadCsv(options?) |
Save the current view as a CSV file. |
See Pagination and CSV export.