Table

Data display

A table of data: <Table.Root> (in a container that scrolls sideways when it is too wide) holds a Table.Header, a Table.Body and an optional Table.Footer, each of Table.Rows of Table.Head (column headings) and Table.Cells, and a Table.Caption that names it. Rows highlight on hover; data-state="selected" on a row marks it selected. A Table.Head with sort (ascending, descending or none) is a sort button with aria-sort that calls onSort. It is the native table, so screen readers read it as one; the app sorts, selects and pages the rows.

import { Table } from '@limerdev/zest';
Table for AI tools (llms.txt)
Use for
Records people compare across columns: invoices, users, time entries.
Don't
Laying out a page or a form: use CSS grid. A list of one-line items: a list.

Examples

Basic

A caption names the table; Table.Footer holds the totals.

Invoices this month
Invoice Customer Status Amount
1042 Acme AB Paid 4 200 kr
1043 Globex Sent 12 800 kr
1044 Initech Overdue 1 650 kr
1045 Umbrella Draft 7 300 kr
Total 25 950 kr

Selection

Rows with a Checkbox: data-state="selected" marks a chosen row. The heading's Checkbox selects all, and is indeterminate while only some are.

0 of 3 users selected
Name Email
Anna Berg anna@example.com
Erik Lund erik@example.com
Sara Ek sara@example.com

Sorting

sort on Table.Head makes the heading a button with aria-sort; onSort is yours, and so is the sorting.

Invoices, sorted by amount
Invoice
1044 Ekgården 12000 kr
1042 Nordlys AB 4200 kr
1043 Bergström & Co 900 kr

Props

Every part also takes class (merged over its defaults), ref (bindable: the element), children, and child (a snippet that renders your own element, with props to spread on it).

Table.Root

No props of its own beyond the common ones.

Table.Header

No props of its own beyond the common ones.

Table.Body

No props of its own beyond the common ones.

Table.Footer

No props of its own beyond the common ones.

Table.Row

No props of its own beyond the common ones.

Table.Head

Prop Type Default Description
onSort (() => void) undefined Called when the sort button is clicked; the app sets the next sort.
sort "none" | "ascending" | "descending" undefined Makes the column sortable: the heading becomes a button with an arrow, and the cell gets aria-sort. none is sortable but not sorted now. Left unset, the column isn't sortable. The app sorts the rows.

Table.Cell

No props of its own beyond the common ones.

Table.Caption

No props of its own beyond the common ones.