Data Table
The interactive tier above Table: column sorting, row selection with select-all, and built-in pagination via the Pagination piece. Caller-owned snippets can customize every header label or body cell without giving up those behaviors. Sorting, selection, and page are each optional-controlled — own them in the parent, or let the table.
| Invoice | Client | Status | Amount | |
|---|---|---|---|---|
| INV-1042 | Acme Inc. | Paid | 1200 | |
| INV-1043 | Globex | Pending | 980 | |
| INV-1044 | Initech | Paid | 3450 | |
| INV-1045 | Umbrella Co. | Overdue | 540 | |
| INV-1046 | Soylent | Draft | 120 |
1–5 of 12
Installation
Copy the piece into your app — it compiles with your build and the code is yours:
puzzle add piece data-table
Pulls in the Pagination piece (a registry dependency) for the footer, and requires the pieces.css tokens merged into your app styles (see Introduction).
Usage
import DataTable from '@/components/ui/DataTable.pzl';
<DataTable columns={ columns } rows={ rows } rowKey="invoice" selectable pageSize={ 5 } />Sorting
| Invoice | Client | Status | Amount |
|---|---|---|---|
| INV-1044 | Initech | Paid | 3450 |
| INV-1042 | Acme Inc. | Paid | 1200 |
| INV-1043 | Globex | Pending | 980 |
| INV-1045 | Umbrella Co. | Overdue | 540 |
| INV-1046 | Soylent | Draft | 120 |
Sort: amount · desc
Header and body cell snippets
| Invoice | Client | Payment status | Amount |
|---|---|---|---|
| INV-1042 | Acme Inc. | Paid | 1200 |
| INV-1043 | Globex | Pending | 980 |
| INV-1044 | Initech | Paid | 3450 |
| INV-1045 | Umbrella Co. | Overdue | 540 |
| INV-1046 | Soylent | Draft | 120 |
Selection
| Invoice | Client | Status | Amount | |
|---|---|---|---|---|
| INV-1042 | Acme Inc. | Paid | 1200 | |
| INV-1043 | Globex | Pending | 980 | |
| INV-1044 | Initech | Paid | 3450 | |
| INV-1045 | Umbrella Co. | Overdue | 540 | |
| INV-1046 | Soylent | Draft | 120 |
0 selected
Pagination
| Invoice | Client | Status | Amount |
|---|---|---|---|
| INV-1042 | Acme Inc. | Paid | 1200 |
| INV-1043 | Globex | Pending | 980 |
| INV-1044 | Initech | Paid | 3450 |
| INV-1045 | Umbrella Co. | Overdue | 540 |
1–4 of 12
Page 1
Accessibility
- Sortable headers set
aria-sorttoascendingordescendingon the active<th>; the attribute is omitted (not set to "none") while unsorted. - Each sortable header has a real
<button>, over its full label and chevron area, so headers are reachable with Tab and cycle asc → desc → off on Enter or Space. Non-sortable headers stay plain text. - Selection uses native
<input type="checkbox">: keyboard-toggleable, each row checkbox carries anaria-labelbuilt from its key, and the header checkbox shows an indeterminate state when the current page is partially selected. - Every button and checkbox sets its focus outline color unconditionally, so focus rings never flash from a default color on the first frame.