Skip to content

DataGrid ​

The grid of TableView and QueryConsole, for the app's own rows, such as the lines of a CSV file. It needs no connection or DatabaseProvider, only the UIProvider of @adecore/ui and the package's Tailwind source.

tsx
import { DataGrid, type GridColumn, type GridRow } from '@adecore/database';
tsx
const columns: GridColumn[] = [
    { name: 'city', type: '', kind: 'text' },
    { name: 'population', type: '', kind: 'integer' }
];

const rows: GridRow[] = [
    { key: '0', number: 1, cells: ['Utrecht', '374238'] },
    { key: '1', number: 2, cells: ['Zwolle', ''] }
];

<DataGrid label="cities.csv" columns={columns} rows={rows} className="h-full" />;

A column aligns by its kind: 'text' to the start, 'integer', 'decimal' and 'float' to the end. type is the type name in the header's tooltip, or empty. A row's key must stay stable, since the selection follows it, and number is the gutter number. cells holds one value per column. null draws as a faint NULL; an empty text is ''.

Without editable no cell can be edited. A person can still select and copy cells as TSV, CSV or JSON, and resize, hide and pin columns.

Sorting ​

The grid draws rows in the given order. With onSortsChange, a header's menu offers Sort ascending, Sort descending and Clear sorting, and reports the sorts by column name. Sort the rows yourself and pass the sorts back as sorts to draw the header arrows:

tsx
const [sorts, setSorts] = useState<readonly GridSort[]>([]);
const sorted = sortRows(rows, sorts);

<DataGrid label="cities.csv" columns={columns} rows={sorted} sorts={sorts} onSortsChange={setSorts} />;

Props ​

PropTypeDefault
columnsreadonly GridColumn[]Required.
rowsreadonly GridRow[]Required. Drawn in this order.
labelstringRequired. The accessible name of the grid.
sortsreadonly GridSort[]The sorted columns by name, in order.
onSortsChange(sorts: readonly GridSort[]) => voidMakes the headers sort.
onFocusedCellChange(cell: FocusedCell | null) => voidThe cell that holds the focus changed, or lost it.
menu(context: GridMenuContext) => ReactNodeItems for the end of the context menu of a cell or a row number.
initialLayoutGridLayoutThe widths, hidden columns and pins to start from, by column name.
onLayoutChange(layout: GridLayout) => voidA person resized, hid or pinned a column.
emptyReactNodeDrawn under the header while there are no rows.
classNamestringIts size.
refRef<HTMLDivElement>

DataGridProps also has props for editing and table rows. A GridRow marks an inserted or deleted row with its state, a GridRowState. A GridSort is a column and a direction, a SortDirection of 'asc' or 'desc'. A GridLayout holds the widths a person set, the hidden columns and the pinned ones. A FocusedCell names a cell by rowKey and column index, and a GridMenuContext hands menu the affected rowKeys and the cell under the pointer. A GridColumn takes its kind from the protocol's ValueKind, and the package also exports the protocol's Cell and Value.

Licenses and third-party notices are listed in each package.