DataTable
Rows with typed cells (bars, sparklines, deltas, badges, status dots) that follow the selection, publish a field on click, sort, paginate and virtualize.
Example
const columns: DataTableColumn[] = [
{ field: 'product', label: 'Product', secondary: 'sku' },
{ field: 'category', label: 'Category', cell: 'badge' },
{ key: 'revenue', field: 'amount', label: 'Revenue', aggregate: 'sum', format: 'currency-compact' },
{ key: 'share', field: 'amount', label: 'Share', aggregate: 'sum', cell: 'bar', share: true },
{ key: 'trend', field: 'amount', label: 'Trend', cell: 'sparkline', over: 'date' },
{ key: 'change', field: 'amount', label: 'Change', cell: 'delta', over: 'date' },
{ field: 'stock', label: 'Status', cell: 'status', tones: { 'In stock': 'positive', 'Low stock': 'warning', Backorder: 'negative' } },
];
<Selection>
<DataTable
data={orders}
groupBy="product"
columns={columns}
select="product"
rank
defaultSort="-revenue"
pageSize={5}
noun="products"
title="Top products"
caption="Ranked by revenue. Change compares the later half of the period with the earlier half."
/>
</Selection>Usage
Columns read field from each row. Give a column its own key when two columns read the same field, as Revenue and Share do above; this works with or without groupBy. Sort by key, with - for descending.
For a complete toolbar with search, typed filters, saved views, column controls and export, use DataExplorer. DataTable also supports ordered sorts, controlled page, pinned numeric-width columns and typed onCellEdit commits. Multi-sort takes precedence over the single-sort API; use manualSort when your data source supplies the ordering.
groupBy collapses rows to one per value and aggregates each column with aggregate; sparkline and delta cells use over to build a series per group. For other shapes, transform derives the displayed rows from the linked rows.
// Raw rows, no groupBy: two columns read "amount"
<DataTable
data={orders}
sort="-amount"
limit={8}
columns={[
{ field: 'product' },
{ field: 'amount', label: 'Revenue' },
{ key: 'amount_bar', field: 'amount', label: 'Size', cell: 'bar' },
]}
/><Selection> the table shows the rows that pass every predicate except its own. With select, clicking a row or pressing Enter toggles that row's value. Past 200 rows (virtualize) only the visible rows render, unless you paginate.Props
DataTable
aggregate.groupBy).Frame and state props shared with the charts (5) · ChartStateProps
DataTableColumn
groupBy).field. Set it when two columns read the same field.text (with optional secondary line), number (mono, right), bar (in-cell bar scaled to the column max), sparkline (an array of numbers), delta (signed pill), badge (tag) or status (dot + text). Or a function returning any node.groupBy: how the field combines across a group.groupBy, for sparkline and delta cells: the series is the aggregate per distinct value of this field. A delta compares the later half of that series with the earlier half.Typed editor
Edit commit
Accessibility
- A
tablerole, orgridwhen rows are interactive. Sortable headers are buttons and reportaria-sort. - In an interactive table, ↑ ↓ move between rows, Home, End, Page Up and Page Down jump, and Enter selects. Selected rows report
aria-selected. - Name the table with
titleoraria-label.