Table view
A read-only table from columns and rows: right-aligned tabular figures, a footer row, a custom cell snippet and a sideways scroll below its minimum width.
Quote lines
| Item | Hours | Total |
|---|---|---|
| Audit and scoping | 12 | $1,800 |
| Build the first module | 40 | $6,000 |
| Handover and training | 8 | $1,200 |
| Total | 60 | $9,000 |
Installation
pnpm add @heyramzi/uiUsage
import { TableView, type TableColumn } from "@heyramzi/ui/components/table-view";<TableView
columns={[
{ key: "item", label: "Item" },
{ key: "hours", label: "Hours", numeric: true, width: "6rem" },
]}
rows={lines}
rowKey={(row) => row.id}
label="Quote lines"
/>Keyboard and accessibility
| Key | Does |
|---|---|
| Tab | Moves focus to the next sort button, row link, row button, checkbox or control in a cell. |
| Enter | On a row link, opens the row. |
| Space Enter | On a row button, opens the row. On a sort button, sorts. On a group header, folds or unfolds the group. |
| Space | On a row's checkbox, selects the row. |
| Shift F10 ContextMenu | On a row with a menu, or anything focused inside it, opens the row menu. |
- With rowHref, each row has one link named by its first column, or by rowLabel.
- With onRowClick and no rowHref, each row has one button with the same name, laid over the row.
- Row checkboxes are named "Select" plus the row's name. The header checkbox selects every row.
- A sortable column head holds a button, and the head reports ascending or descending.
- The table is named by label and reports busy while loading.
- A row menu also opens on right-click or a long press. A row with no link or button of its own takes focus itself, so the keys reach it.
API reference
columnsrequiredTableColumn<Row>[]rowsrequiredRow[]rowKeyrequired(row: Row) => string- What names a row, so a filter keeps its rows in place.
labelrequiredstring- What the table is, for a screen reader.
footerRow- A totals row, drawn under the body in the same columns.
cellSnippet<[TableCell<Row>]>- Draws a cell its own way. Print `text` for the plain case.
rowClass(row: Row) => string | undefinedminWidthstring- Below this width the table scrolls sideways inside its frame. Defaults to the columns' own widths (8rem a text column, 5rem a number), so a phone scrolls rather than splits words. Pass "0" for a table that should squeeze.
classstringsortbindableSortState<Row>- Default
null - The sorted column and its direction. Bind it; columns with `sortable` set it.
rowHref(row: Row) => string | undefined- Where a row goes. Draws a real link over the row, so middle-click and cmd-click work.
onRowLink(row: Row, event: MouseEvent) => void- Runs on a plain left click of the row link. Call `event.preventDefault()` to open in place; a modified click still follows `href`.
rowLabel(row: Row) => string- The link's accessible name. Defaults to the row's first column text.
selectableboolean- Default
false - Adds a checkbox column with a select-all in the head.
selectedbindableSet<string>- Default
new Set<string>() - The `rowKey` of every checked row. Bind it.
selectAllLabelstring- Default
"Select all rows" selectRowLabel(row: Row) => stringopenColumnLabelstring- Default
"Open" - The hidden head of the last column, the one holding each row's link or button.
rowMenuSnippet<[Row]>- The items of a row menu: `ContextMenu.Item`s. Right-click, a long press, Shift+F10 or the ContextMenu key opens it.
group(row: Row) => string | null- Rows that return the same key sit under one header row, and `null` rows sit with no header. Order `rows` so a group is contiguous.
groupHeaderSnippet<[TableGroup<Row>]>- Draws a group's header. Prints the key when left out.
collapsibleboolean- Default
false - Makes each group header a button that folds its rows.
collapsedbindableSet<string>- Default
new Set<string>() - The keys of the folded groups. Bind it.
headSnippet<[TableColumn<Row>]>- Draws a column head its own way, an icon or a colour. Print `column.label` for the plain case.
onRowClick(row: Row) => void- The row opens in place, from a button over the row named like the row link.
expanded(row: Row) => boolean- Whether a row shows its `subRow`.
subRowSnippet<[Row]>- A full-width row under the row, for detail.
emptySnippet- Drawn across every column when there are no rows.
trailingSnippet- Drawn across every column under the last row: a load-more sentinel or a spinner.
loadingboolean- Default
false - Draws placeholder rows in the same frame instead of `rows`.
skeletonRowsnumber- Default
5
| Prop | Type | Default |
|---|---|---|
columns required | TableColumn<Row>[] | |
rows required | Row[] | |
rowKey required What names a row, so a filter keeps its rows in place. | (row: Row) => string | |
label required What the table is, for a screen reader. | string | |
footer A totals row, drawn under the body in the same columns. | Row | |
cell Draws a cell its own way. Print `text` for the plain case. | Snippet<[TableCell<Row>]> | |
rowClass | (row: Row) => string | undefined | |
minWidth Below this width the table scrolls sideways inside its frame. Defaults to the columns' own widths (8rem a text column, 5rem a number), so a phone scrolls rather than splits words. Pass "0" for a table that should squeeze. | string | |
class | string | |
sort bindable The sorted column and its direction. Bind it; columns with `sortable` set it. | SortState<Row> | null |
rowHref Where a row goes. Draws a real link over the row, so middle-click and cmd-click work. | (row: Row) => string | undefined | |
onRowLink Runs on a plain left click of the row link. Call `event.preventDefault()` to open in place; a modified click still follows `href`. | (row: Row, event: MouseEvent) => void | |
rowLabel The link's accessible name. Defaults to the row's first column text. | (row: Row) => string | |
selectable Adds a checkbox column with a select-all in the head. | boolean | false |
selected bindable The `rowKey` of every checked row. Bind it. | Set<string> | new Set<string>() |
selectAllLabel | string | "Select all rows" |
selectRowLabel | (row: Row) => string | |
openColumnLabel The hidden head of the last column, the one holding each row's link or button. | string | "Open" |
rowMenu The items of a row menu: `ContextMenu.Item`s. Right-click, a long press, Shift+F10 or the ContextMenu key opens it. | Snippet<[Row]> | |
group Rows that return the same key sit under one header row, and `null` rows sit with no header. Order `rows` so a group is contiguous. | (row: Row) => string | null | |
groupHeader Draws a group's header. Prints the key when left out. | Snippet<[TableGroup<Row>]> | |
collapsible Makes each group header a button that folds its rows. | boolean | false |
collapsed bindable The keys of the folded groups. Bind it. | Set<string> | new Set<string>() |
head Draws a column head its own way, an icon or a colour. Print `column.label` for the plain case. | Snippet<[TableColumn<Row>]> | |
onRowClick The row opens in place, from a button over the row named like the row link. | (row: Row) => void | |
expanded Whether a row shows its `subRow`. | (row: Row) => boolean | |
subRow A full-width row under the row, for detail. | Snippet<[Row]> | |
empty Drawn across every column when there are no rows. | Snippet | |
trailing Drawn across every column under the last row: a load-more sentinel or a spinner. | Snippet | |
loading Draws placeholder rows in the same frame instead of `rows`. | boolean | false |
skeletonRows | number | 5 |