Skip to main content
  1. Docs
  2. Components
  3. 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

table.tsx
// 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.

PropTypeDefaultWhat it does
labelstringrequiredNames the table: "Users".
rows · rowId · rowLabelRow[] · (row) => stringrequiredThe rows on show (this page), each one's stable id, and its name: for its link, checkbox and menu.
columnsTableColumn<Row>[]requiredid, header, cell(row); and sortable, sortFirst, align, numeric, width, primary, priority.
sort · defaultSort · onSortChangeTableSort | nullnull{ column, direction }, or null for the server's own order. The rows arrive sorted.
selectablebooleanfalseA checkbox per row; the header's selects or clears the page.
selected · defaultSelected · onSelectedChangestring[][]The chosen rows' ids; they may include rows on other pages.
rowSelectable · rowUnselectableReason(row) => boolean · (row) => stringevery rowA 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.
currentRowstring—The id of the row whose record is open beside the list: aria-current, tinted.
loading · loadingRowsboolean · numberfalse · 5Placeholder rows with none yet; with rows, a busy line. Loading is announced.
empty · errorReactNode"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 · onExpandedChangestring[][]The open rows' ids.
stickyFirstColumnbooleanfalseThe first column stays as a matrix scrolls sideways.

03

Parts

Each part carries a data-slot, for tests and placement.

data-slotElementWhat 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.

users.tsx
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.

audit-log.tsx
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" },
];
Next — TableAccessibility