Birch UI v0.1
Pricing

Rows & row IDs

Pass rows as plain objects, give them stable IDs with getRowId, and understand the display rows the grid renders.

Open .md

Rows are plain JavaScript objects passed as the rows option. The grid never clones or wraps them: the objects you pass are the objects you get back from getRows(), getSelectedRows() and every event payload. Type them once with the grid's generic parameter and the whole API follows.

technicians-grid.ts
import { createGrid, type ColumnDef } from '@birchui/core';

interface Technician {
  employeeId: string;
  name: string;
  region: string;
  skills: string[];
  openTickets: number;
  certifiedUntil: string;
}

const technicians: Technician[] = [
  { employeeId: 'T-0142', name: 'Amira Haddad', region: 'North', skills: ['HVAC', 'Electrical'], openTickets: 3, certifiedUntil: '2027-01-31' },
  { employeeId: 'T-0187', name: 'Lukas Brandt', region: 'Central', skills: ['Plumbing'], openTickets: 7, certifiedUntil: '2026-09-30' },
  { employeeId: 'T-0203', name: 'Priya Nair', region: 'South', skills: ['Electrical', 'Solar'], openTickets: 1, certifiedUntil: '2027-04-15' },
];

const columns: ColumnDef<Technician>[] = [
  { field: 'employeeId', header: 'ID', width: 100 },
  { field: 'name', flex: 1 },
  { field: 'region' },
  { id: 'skills', header: 'Skills', valueGetter: (t) => t.skills.join(', ') },
  { field: 'openTickets', header: 'Open tickets', type: 'number' },
  { field: 'certifiedUntil', header: 'Certified until', type: 'date' },
];

const grid = createGrid<Technician>(document.querySelector('#technicians')!, {
  columns,
  rows: technicians,
  getRowId: (t) => t.employeeId,
});

Row IDs#

Every row has a string ID. IDs drive selection, expansion state, transactions, getRowById() and focus restoration after data changes.

Provide getRowId whenever rows have a key#

getRowId(row, index) returns the ID for a row. Use your primary key:

TypeScript
createGrid<Order>(container, {
  columns,
  rows: orders,
  getRowId: (order) => order.id,
});

With getRowId, a row keeps its identity even when you replace the object, for example after re-fetching from the server. Selection survives a refresh and applyTransaction({ update }) can match fresh objects to existing rows.

Without getRowId#

If you omit getRowId, the grid assigns IDs such as r1, r2 and remembers them per object instance. Passing the same objects again keeps their IDs. Passing new objects, even with identical contents, creates new rows with new IDs, which clears their selection and expansion state.

Looking rows up#

TypeScript
const id = grid.getRowId(technicians[0]);
const lukas = grid.getRowById('T-0187');
const all = grid.getRows();
GridApiinterface@birchui/coreFull reference
MemberTypeDescription
getRows()() => readonly TRow[]—
getRowId()(row: TRow) => string—
getRowById()(id: string) => TRow | undefined—
getDisplayRows()() => readonly DisplayRow<TRow>[]—
getAllDisplayRows()() => readonly DisplayRow<TRow>[]—
getRenderedRows()() => readonly DisplayRow<TRow>[]—
getDisplayRow()(rowIndex: number) => DisplayRow<TRow> | undefined—

Source rows and display rows#

The grid keeps two lists:

  • Source rows are your objects, in the order you passed them. getRows() returns them.
  • Display rows are what the grid renders after filtering, sorting, pagination and any module stages such as grouping. getDisplayRows() returns them, and every rowIndex in the API and in events is an index into this list.
  • All display rows are the same list before pagination slices it into pages. getAllDisplayRows() returns them. Without pagination the two lists are identical; with pagination, getDisplayRows() holds only the current page.
TypeScript
const onThisPage = grid.getDisplayRows().length;
const matchingFilters = grid.getAllDisplayRows().filter((row) => row.kind === 'data').length;
pageInfo.textContent = `${onThisPage} shown, ${matchingFilters} technicians match`;

Each display row is a DisplayRow that wraps your data with rendering state:

TypeScript
const first = grid.getDisplayRow(0);
if (first?.kind === 'data') {
  console.info(first.id, first.data?.name, first.sourceIndex);
}
Kind Produced by data
data Every source row that passes the filters The source row
group Row grouping and tree data (Grid Pro) undefined, see group and aggregates
detail Master/detail (Grid Pro) The master row
total Group totals and pivot totals (Grid Pro) undefined, see aggregates
DisplayRowinterface@birchui/coreFull reference
PropertyTypeDescription
kindDisplayRowKind—
idstring—
dataTRow | undefined—
depthnumber—
sourceIndexnumber—
expandableboolean—
expandedboolean—
parentIdoptionalstring—
groupoptionalDisplayRowGroup<TRow>—
aggregatesoptionalRecord<string, unknown>—
fullWidthoptionalboolean—
heightoptionalnumber—

getRenderedRows() returns only the display rows that currently have DOM elements, which is the visible window plus the overscan. See Virtualization & performance.

Converting between indexes and rows#

Events report both the row and its rowIndex. To go the other way:

TypeScript
grid.on('cellClick', ({ row, rowIndex, colId }) => {
  const displayRow = grid.getDisplayRow(rowIndex);
  console.info(colId, row?.name, displayRow?.id);
});

const index = grid.getDisplayRows().findIndex((r) => r.id === 'T-0203');
if (index >= 0) grid.scrollToRow(index, 'center');

Row classes and stripes#

rowClass(displayRow) returns classes for a row element. It runs for every rendered row, so keep it cheap.

TypeScript
createGrid<Technician>(container, {
  columns,
  rows: technicians,
  getRowId: (t) => t.employeeId,
  stripes: true,
  rowClass: (row) => (row.data && row.data.openTickets > 5 ? 'row-overloaded' : undefined),
});
CSS
.lq-grid .lq-row.row-overloaded {
  background: #fff8e6;
}

Every row element also carries built-in classes you can target: lq-row, lq-row-even or lq-row-odd, lq-row-data, lq-row-group, lq-row-detail or lq-row-total by kind, lq-row-selected and lq-row-focused.

stripes: true shades odd rows with --lq-row-alt. Because the grid's own row rules use two classes, give your overrides at least three (as above) so they win regardless of stylesheet order. See Theming.

Row height#

rowHeight is a number for uniform rows or a function of the display row for variable heights. Without it, the height follows density: 28 pixels for compact, 34 for normal and 42 for comfortable.

TypeScript
createGrid<Technician>(container, {
  columns,
  rows: technicians,
  rowHeight: (row) => (row.data && row.data.skills.length > 2 ? 56 : 36),
});

Uniform heights are the fastest path. Variable heights are supported at any scale; the grid measures offsets once per data change, not per scroll. If the function throws or returns something that is not a positive number, that row falls back to the default height and a thrown error is reported with console.error. See Virtualization & performance.

Empty grids#

When no display rows remain, either because rows is empty or because filters removed everything, the grid shows emptyMessage in the body. The default is "No rows to show".

TypeScript
createGrid(container, {
  columns,
  rows: [],
  emptyMessage: 'No technicians match these filters',
});

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