DataTable
Rows of data under column headings, sorted by pressing a sortable heading.
Stability: experimental
Props
| Prop | Type | Default | Means |
|---|---|---|---|
label | string | What 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). | |
rows | Record<string, string | number>[] | The rows, each a record of the columns' fields. | |
sort | string | bindable("") | The column it is sorted by; empty for the rows' own order. Bind it with bind:sort={name}. |
descending | boolean | bindable(false) | Whether the order is reversed. Bind it with bind:descending={name}. |
States
| State | Looks like |
|---|---|
default | A bordered table with a raised heading row. |
sorted | The sorted column's heading shows an arrow up (ascending) or down (descending). |
Accessibility
| role | table, with rows, column headers and cells |
| name | The label prop; each sort button is "Sort by <column>". |
| focus | Tab reaches each sortable heading's button. |
| keyboard | Enter and Space on a sortable heading sort by it, then reverse the order. |
| notes | Each 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} />