Skip to content

Table

Contributors
Role
AdaLead128
GraceEngineer95
AlanEngineer142

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.

<script>
import Table from "@invisible-ui/svelte/Table.svelte";
</script>
PropTypeDefaultDescription
columns *TableColumnDef[]—Columns ({ key, header, sortable?, align?, hideable? }).
rows *TableRow[]—Row objects keyed by column.key.
sortSortState | nullnullCurrent sort ({ key, direction }).
onSortToggle((key: string) => void) | undefinedundefinedCalled when a sortable header is toggled.
captionstring | undefinedundefinedAccessible caption.
hideCaptionbooleanfalseVisually 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 | numberdefaultGetRowIdStable row key.
selectionColumnbooleanfalseRender 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) | undefinedundefinedMarks a row selected (data-selected styling hook). Used with selectionColumn.
cellSnippet<[{ row: TableRow; column: TableColumnDef; value: unknown; rowIndex: number }]> | undefinedundefinedCustom cell content. Defaults to the cell value.
selectionHeaderSnippet | undefinedundefinedHeader cell content of the selection column.
selectionCellSnippet<[{ row: TableRow; rowId: string | number; rowIndex: number }]> | undefinedundefinedBody cell content of the selection column, rendered for every row.

Use the cell snippet ({ row, column, value, rowIndex }) for custom cell rendering.

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.

  • A real <table> with <caption>; sortable headers expose aria-sort.
<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)
}
/>

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.