DataTable
Sortable sticky headers, row selection, an active row, and a loading skeleton with the real column widths.
| INV-2043 | Acme Industries | €4,280 | due | 2026-08-12 | Edit INV-2043Delete INV-2043 | |
| INV-2042 | Northwind Trading | €1,150 | paid | 2026-08-09 | Edit INV-2042Delete INV-2042 | |
| INV-2041 | Globex | €9,600 | overdue | 2026-07-28 | Edit INV-2041Delete INV-2041 | |
| INV-2040 | Initech | €320 | paid | 2026-07-21 | Edit INV-2040Delete INV-2040 | |
| INV-2039 | Soylent Corp | €2,745 | due | 2026-07-15 | Edit INV-2039Delete INV-2039 | |
| INV-2038 | Umbrella Health | €640 | paid | 2026-07-02 | Edit INV-2038Delete INV-2038 |
import { DataTable, applyTableSort, type Column, type TableSort } from '@objectifthunes/whiteboard'
const columns: Column<Invoice>[] = [
{ id: 'id', header: 'Invoice', cell: r => r.id, sortable: true, sortValue: r => r.id, width: 110 },
{ id: 'amount', header: 'Amount', cell: r => money(r.amount),
align: 'right', sortable: true, sortValue: r => r.amount },
{ id: 'status', header: 'Status', cell: r => <Pill tone={TONES[r.status]}>{r.status}</Pill> },
{ id: 'actions', header: '', align: 'right',
cell: r => <IconButton icon={<Pencil size={13} />} label={`Edit ${r.id}`} /> },
]
<DataTable
columns={columns}
rows={applyTableSort(invoices, columns, sort)} // or pass server-sorted rows straight through
rowKey={r => r.id}
sort={sort}
onSortChange={setSort}
selectedKeys={selected}
onSelectionChange={setSelected}
onRowClick={setOpenRow}
activeKey={openRow?.id}
loading={isLoading}
empty={<EmptyState title="No invoices" description="Invoices you issue will show up here." />}
/>Presentational on purpose. Sorting, paging and filtering are reported up, never done here, so the same component serves a client-side array and a server-paged endpoint. For client-side sorting run rows through applyTableSort — three lines at the call site, and no hidden state.
applyTableSortsorts nullish values last in both directions, because "empty" is not smaller than everything, it is absent. nextTableSort is the header click rule: flip direction on the same column, start a new column ascending.
Flip the switches above. loading renders skeleton rows using the real column widths, so nothing shifts when the data lands. Idle sort arrows stay invisible until you hover a header, which keeps the header from becoming a row of noise.
Select-all applies to the rows on screen and keeps keys from other pages, so paging through a table does not silently drop your earlier selection. Row clicks ignore anything landing on an input, button, a or label, so cell actions and the checkbox do not also open the row.
A table cannot usefully shrink, so it scrolls sideways inside its own container rather than reflowing into unreadable columns. When the row is simple enough to reflow, use RowCard with ItemList instead. Bulk actions for the selection belong in StickyBar.