- Docs
- Components
- Data display
Table
The one way to show records. Columns and rows in; sorting, selection, row actions and every state built in.
- Import
- @qeetrix/react
- Status
- StableSince 0.0.2
- Renders
<table>Server-rendered- Tested
- WCAG 2.2 AAaxe on every pull request
01
Import
// From the package: a build keeps only what it uses.
import { Table, TableColumn, TableSort } from "@qeetrix/react";
// Or from its own path.
import { Table, TableColumn, TableSort } from "@qeetrix/react/table";02
Props
And every native attribute of the element it renders.
| Prop | Type | Default | What it does |
|---|---|---|---|
label | string | required | Names the table: "Users". |
rows · rowId · rowLabel | Row[] · (row) => string | required | The rows on show (this page), each one's stable id, and its name: for its link, checkbox and menu. |
columns | TableColumn<Row>[] | required | id, header, cell(row); and sortable, sortFirst, align, numeric, width, primary, priority. |
sort · defaultSort · onSortChange | TableSort | null | null | { column, direction }, or null for the server's own order. The rows arrive sorted. |
selectable | boolean | false | A checkbox per row; the header's selects or clears the page. |
selected · defaultSelected · onSelectedChange | string[] | [] | The chosen rows' ids; they may include rows on other pages. |
rowSelectable · rowUnselectableReason | (row) => boolean · (row) => string | every row | A row that can't be chosen: its checkbox disabled, described by the reason; the header's leaves it out. |
bulkActions · toolbar | (ids) => ReactNode · ReactNode | — | The bar above: the toolbar, or while rows are chosen, the count, bulkActions and Clear. |
rowActions | (row) => ReactNode | — | MenuItems, in a menu at each row's end; nothing leaves that row without one. |
rowHref · renderRowLink · onRowClick | (row) => … | — | Each row opens its record: the primary cell holds the link, and a click elsewhere on the row follows it. |
currentRow | string | — | The id of the row whose record is open beside the list: aria-current, tinted. |
loading · loadingRows | boolean · number | false · 5 | Placeholder rows with none yet; with rows, a busy line. Loading is announced. |
empty · error | ReactNode | "No results" | In place of the rows: an EmptyState, a DataState. |
rowDepth · rowHasChildren · rowPath | (row) => … | — | Tree rows that fold, in tree order: a tree grid, ← folds and → opens. |
expanded · defaultExpanded · onExpandedChange | string[] | [] | The open rows' ids. |
stickyFirstColumn | boolean | false | The first column stays as a matrix scrolls sideways. |
03
Parts
Each part carries a data-slot, for tests and placement.
| data-slot | Element | What it is |
|---|---|---|
table | <div> | The bar, the table and its announcements. |
table-bar | <div> | The toolbar, or the selection's bar. |
table-toolbar | <div> | toolbar, filling the bar. |
table-scroll | <div> | Scrolls sideways only while it overflows: a named region then. |
table-element | <table> | aria-label; aria-busy while loading. |
table-head | <th scope="col"> | aria-sort when sorted. |
table-sort | <button> | A sortable header's button. |
table-row | <tr> | data-selected; data-clickable. |
table-cell | <td> | data-align, data-numeric. |
table-row-link | <a> | The primary cell's link, or a <button> with onRowClick alone. |
04
Server-paged
The table holds the sort and the selection; the server sorts and pages. Send both, show what comes back.
const [sort, setSort] = useState<TableSort | null>(null);
const [offset, setOffset] = useState(0);
const { data, isFetching } = useUsers({ sort, offset, limit: 25 });
<Table rows={data?.rows ?? []} sort={sort} onSortChange={setSort} loading={isFetching} … />
<Pagination offset={offset} pageSize={25} total={data?.total} onOffsetChange={setOffset} />05
Narrow screens
priority: low columns hide under 640px, medium under 480px; wider still, the table scrolls itself.
const columns: TableColumn<Event>[] = [
{ id: "event", header: "Event", cell: (e) => e.name, primary: true },
{ id: "actor", header: "Actor", cell: (e) => e.actor, priority: "medium" },
{ id: "ip", header: "IP address", cell: (e) => e.ip, priority: "low" },
];