Duolith docs

DataTable

Rows of data under column headings, sorted by pressing a sortable heading.

Stability: experimental

Props

PropTypeDefaultMeans
labelstringWhat the table holds; its accessible name.
columns{ key: string; label: string; sortable?: boolean; numeric?: boolean }[]The columns, in order: the field each shows, its heading, whether it sorts, and whether it is numbers (aligned to the end).
rowsRecord<string, string | number>[]The rows, each a record of the columns' fields.
sortstringbindable("")The column it is sorted by; empty for the rows' own order. Bind it with bind:sort={name}.
descendingbooleanbindable(false)Whether the order is reversed. Bind it with bind:descending={name}.

States

StateLooks like
defaultA bordered table with a raised heading row.
sortedThe sorted column's heading shows an arrow up (ascending) or down (descending).

Accessibility

roletable, with rows, column headers and cells
nameThe label prop; each sort button is "Sort by <column>".
focusTab reaches each sortable heading's button.
keyboardEnter and Space on a sortable heading sort by it, then reverse the order.
notesEach sortable column header has aria-sort: ascending, descending or none (sorted=… in the markup; on native the sorted one's accessibility value says which way). It is a table, not a grid, because it has no keys that move from cell to cell.

Theme tokens

color.border color.surface color.raised color.muted color.ink color.primary space.1 space.2 space.3 text.label text.body

Example

<DataTable label="Orders" columns={columns} rows={orders} bind:sort={sort} />