Birch UI v0.1
Pricing

Grid API reference

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

Open .md

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.

TypeScript
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.

See Sorting and Filtering.

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.
TypeScript
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.

Methods added by Grid Pro#

Full interface#

GridApiinterface@birchui/coreFull reference
MemberTypeDescription
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()optional(colIds: ((keyof TRow & string) | (string & {}))[] | null) => voidAdded by @birchui/grid-pro when its module is installed.
getGroupBy()optional() => string[]Added by @birchui/grid-pro when its module is installed.
expandToLevel()optional(level: number) => voidAdded by @birchui/grid-pro when its module is installed.
setPivot()optional(options: PivotOptions | null) => voidAdded by @birchui/grid-pro when its module is installed.
getPivot()optional() => PivotOptions | nullAdded by @birchui/grid-pro when its module is installed.
getPivotResult()optional() => PivotMatrix | nullAdded by @birchui/grid-pro when its module is installed.
getColumnAggregate()optional(colId: string, aggFunc?: AggFuncInput) => unknownAdded by @birchui/grid-pro when its module is installed.
getCellRanges()optional() => CellRange[]Added by @birchui/grid-pro when its module is installed.
setCellRange()optional(range: CellRange | null) => voidAdded by @birchui/grid-pro when its module is installed.
addCellRange()optional(range: CellRange) => voidAdded by @birchui/grid-pro when its module is installed.
clearCellRanges()optional() => voidAdded by @birchui/grid-pro when its module is installed.
getRangeValues()optional(rangeIndex?: number) => unknown[][]Added by @birchui/grid-pro when its module is installed.
onRangeChanged()optional(listener: (event: RangeChangedEvent) => void) => () => voidAdded by @birchui/grid-pro when its module is installed.
copyToClipboard()optional() => Promise<void>Added by @birchui/grid-pro when its module is installed.
cutToClipboard()optional() => Promise<void>Added by @birchui/grid-pro when its module is installed.
pasteFromClipboard()optional() => Promise<number>Added by @birchui/grid-pro when its module is installed.
pasteText()optional(text: string) => numberAdded by @birchui/grid-pro when its module is installed.
setDetailExpanded()optional(rowId: string, expanded: boolean) => voidAdded by @birchui/grid-pro when its module is installed.
isDetailExpanded()optional(rowId: string) => booleanAdded by @birchui/grid-pro when its module is installed.
buildExcelWorkbook()optional(options?: ExcelExportOptions) => XlsxWorkbookAdded by @birchui/grid-pro when its module is installed.
exportExcel()optional(options?: ExcelExportOptions) => Promise<void>Added by @birchui/grid-pro when its module is installed.
getExcelBlob()optional(options?: ExcelExportOptions) => Promise<Blob>Added by @birchui/grid-pro when its module is installed.
importExcel()optional(data: Blob | ArrayBuffer | Uint8Array, options?: ExcelImportOptions) => Promise<ExcelImportResult<TRow>>Added by @birchui/grid-pro when its module is installed.
getToolPanelColumns()optional() => ResolvedColumn<TRow>[]Added by @birchui/grid-pro when its module is installed.
openToolPanel()optional(id: ToolPanelId) => voidAdded by @birchui/grid-pro when its module is installed.
closeToolPanel()optional() => voidAdded by @birchui/grid-pro when its module is installed.
getOpenedToolPanel()optional() => ToolPanelId | nullAdded by @birchui/grid-pro when its module is installed.
setSideBarVisible()optional(visible: boolean) => voidAdded by @birchui/grid-pro when its module is installed.
isSideBarVisible()optional() => booleanAdded by @birchui/grid-pro when its module is installed.
createRangeChart()optional(params?: CreateRangeChartParams<TRow>) => RangeChartRef | nullAdded by @birchui/grid-pro when its module is installed.
getChartRefs()optional() => RangeChartRef[]Added by @birchui/grid-pro when its module is installed.
elementreadonlyHTMLElementInherited from Widget.
update()(options: Partial<GridOptions<TRow>>) => voidInherited from Widget.
on()<K extends keyof TEvents & string>(event: K, listener: Listener<TEvents[K]>) => () => voidInherited from Widget.
destroy()() => voidInherited from Widget.
moveRow()(row: string | TRow, toIndex: number) => booleanInherited from GridFeatureApi.
getPinnedTopRows()() => readonly TRow[]Inherited from GridFeatureApi.
getPinnedBottomRows()() => readonly TRow[]Inherited from GridFeatureApi.
flashCells()(params?: FlashCellsParams<TRow> | undefined) => voidInherited from GridFeatureApi.
find()(text: string, options?: FindOptions) => FindMatch<TRow>[]Inherited from GridFeatureApi.
findNext()() => FindMatch<TRow> | nullInherited from GridFeatureApi.
findPrevious()() => FindMatch<TRow> | nullInherited from GridFeatureApi.
getFindMatches()() => FindMatch<TRow>[]Inherited from GridFeatureApi.
getActiveFindMatch()() => FindMatch<TRow> | nullInherited from GridFeatureApi.
clearFind()() => voidInherited from GridFeatureApi.
openFindBar()() => voidInherited from GridFeatureApi.
closeFindBar()() => voidInherited from GridFeatureApi.
print()() => voidInherited from GridFeatureApi.

↑ ↓ to move, Enter to open, Esc to close