Table
| Role | ||
|---|---|---|
| Ada | Lead | 128 |
| Grace | Engineer | 95 |
| Alan | Engineer | 142 |
The pure data grid: columns, cells and sortable headers with aria-sort. It’s
controlled — sorting is reported via onSortToggle; for the batteries-included
shell (config, views, pagination) see TableSet.
Import
Section titled “Import”<script> import Table from "@invisible-ui/svelte/Table.svelte";</script><script setup> import { Table } from "@invisible-ui/vue";</script>import { Table } from "@invisible-ui/react";<script type="module"> import "@invisible-ui/elements/define";</script>
<ds-table></ds-table>| Prop | Type | Default | Description |
|---|---|---|---|
columns * | TableColumnDef[] | — | Columns ({ key, header, sortable?, align?, hideable? }). |
rows * | TableRow[] | — | Row objects keyed by column.key. |
sort | SortState | null | null | Current sort ({ key, direction }). |
onSortToggle | ((key: string) => void) | undefined | undefined | Called when a sortable header is toggled. |
caption | string | undefined | undefined | Accessible caption. |
hideCaption | boolean | false | Visually hide the caption. |
getValue | (row: TableRow, key: string) => unknown | (row, key) => row[key] | Read a cell value (override for nested/derived data). |
getRowId | (row: TableRow, index: number) => string | number | defaultGetRowId | Stable row key. |
selectionColumn | boolean | false | Render a leading structural column for row selection. The content comes from the selectionHeader and selectionCell snippets; this component stays free of the selection policy itself. |
isRowSelected | ((row: TableRow, rowIndex: number) => boolean) | undefined | undefined | Marks a row selected (data-selected styling hook). Used with selectionColumn. |
cell | Snippet<[{ row: TableRow; column: TableColumnDef; value: unknown; rowIndex: number }]> | undefined | undefined | Custom cell content. Defaults to the cell value. |
selectionHeader | Snippet | undefined | undefined | Header cell content of the selection column. |
selectionCell | Snippet<[{ row: TableRow; rowId: string | number; rowIndex: number }]> | undefined | undefined | Body cell content of the selection column, rendered for every row. |
| Prop | Type | Default | Description |
|---|---|---|---|
columns * | TableColumnDef[] | — | |
rows * | TableRow[] | — | |
sort | SortState | null | null | The active sort, reflected on the headers (controlled). |
onSortToggle | (key: string) => void | undefined | Called with the column key when a sortable header is activated. |
caption | string | undefined | Accessible name for the table (rendered as a <caption>). |
hideCaption | boolean | false | Visually hide the caption (still available to assistive tech). |
getValue | (row: TableRow, key: string) => unknown | (row: TableRow, key: string) => row[key] | Reads a row's value for a column (defaults to row[key]). |
getRowId | (row: TableRow, index: number) => string | number | defaultGetRowId | Stable row key (defaults to row.id, falling back to the index). |
selectionColumn | boolean | false | Render a leading structural column for row selection. The content comes from the selectionHeader and selectionCell slots; this component stays free of the selection policy itself. |
isRowSelected | (row: TableRow, rowIndex: number) => boolean | undefined | Marks a row selected (data-selected styling hook). Used with selectionColumn. |
Slots: cell, selectionCell, selectionHeader.
| Prop | Type | Default | Description |
|---|---|---|---|
columns * | TableColumnDef[] | — | |
rows * | TableRow[] | — | |
sort | SortState | null | null | The active sort, reflected on the headers (controlled). |
onSortToggle | (key: string) => void | — | Called with the column key when a sortable header is activated. |
caption | string | — | Accessible name for the table (rendered as a <caption>). |
hideCaption | boolean | false | Visually hide the caption (still available to assistive tech). |
getValue | (row: TableRow, key: string) => unknown | defaultGetValue | Reads a row's value for a column (defaults to row[key]). |
getRowId | (row: TableRow, index: number) => string | number | defaultGetRowId | Stable row key (defaults to row.id, falling back to the index). |
selectionColumn | boolean | false | Render a leading structural column for row selection. Its content comes from selectionHeader and renderSelectionCell; this component stays free of the selection policy itself. |
isRowSelected | (row: TableRow, rowIndex: number) => boolean | — | Marks a row selected (data-selected styling hook). Used with selectionColumn. |
renderCell | (context: TableCellContext) => ReactNode | — | Custom cell content. Defaults to the cell value, as text. |
selectionHeader | ReactNode | — | Header cell content of the selection column. |
renderSelectionCell | (context: TableSelectionCellContext) => ReactNode | — | Body cell content of the selection column, rendered for every row. |
| Attribute | Reactive | Description |
|---|---|---|
caption | yes | |
hide-caption | yes | |
sort-key | yes | |
sort-direction | yes | |
selection-column | yes | |
empty-text | yes |
Reactive attributes re-render the element when they change after the first render.
Properties: columns, rows, sort, getValue, getRowId, renderCell, isRowSelected, renderSelectionHeader, renderSelectionCell, renderEmpty. renderEmpty supplies rich DOM content when there are no rows; empty-text is the text-only alternative.
Emits: sort-toggle (detail.key) after a sortable header is activated.
Use the cell snippet ({ row, column, value, rowIndex }) for custom cell
rendering.
Row selection column
Section titled “Row selection column”With selectionColumn, the table renders a structural first column and two
snippets to fill it: selectionHeader for the <th> (the select-all control
lives here) and selectionCell ({ row, rowId, rowIndex }) for each row’s
control. The table itself holds no selection state: pair the snippets
with your own state or use
Table Set, which wires
controlled row selection on top of this column — see its
Row selection
section. isRowSelected only paints data-selected on the row for styling.
Accessibility
Section titled “Accessibility”- A real
<table>with<caption>; sortable headers exposearia-sort.
Example
Section titled “Example”<Table caption="Team" columns={[{ key: "name", header: "Name", sortable: true }]} rows={rows} />In Elements, structured data is assigned through properties. The component reports a requested sort and leaves row ordering to the application:
<ds-table caption="Team"></ds-table>
<script type="module"> const table = document.querySelector("ds-table"); table.columns = [ { key: "name", header: "Name", sortable: true }, { key: "role", header: "Role" }, ]; table.rows = people; table.addEventListener("sort-toggle", ({ detail }) => { table.sort = nextSort(table.sort, detail.key); table.rows = sortPeople(people, table.sort); });</script>In React, renderCell replaces the cell snippet, and the selection column
takes selectionHeader (markup) and renderSelectionCell. Cell values render
as text unless renderCell returns markup of your own:
<Table caption="Team" columns={columns} rows={rows} sort={sort} onSortToggle={(key) => setSort(nextSort(sort, key))} renderCell={({ column, value }) => column.key === "email" ? <a href={`mailto:${value}`}>{String(value)}</a> : String(value) }/>Empty state in Elements
Section titled “Empty state in Elements”Keep an empty result inside the table instead of hiding the table and
coordinating a separate message. Use empty-text for plain text. The component
renders one body cell spanning every visible structural column and removes it
when rows becomes non-empty.
<ds-table caption="Columns" empty-text="Choose a table from the catalog"></ds-table>For structured content, assign a renderEmpty function that returns a DOM
node. Returned strings are inserted as text and are never parsed as HTML.
Themeable via --ds-table-*. The header stays transparent by default. Set
--ds-table-header-background on the table or an ancestor when the header
needs its own fill; this component token does not create a new global surface
role.