import { Table } from "@senvenli/react/collection";
import { Badge, Text } from "@senvenli/react/display";
import { Stack } from "@senvenli/react/layout";
const ORDERS = [
{ id: "SO-1042", customer: "Ada Lovelace", email: "ada@example.com", date: "Mar 18, 2026", total: 248.5, isPaid: true },
{ id: "SO-1043", customer: "Grace Hopper", email: "grace@example.com", date: "Mar 18, 2026", total: 96, isPaid: false },
{ id: "SO-1044", customer: "Alan Turing", email: "alan@example.com", date: "Mar 17, 2026", total: 1290, isPaid: true },
{ id: "SO-1045", customer: "Katherine Johnson", email: "katherine@example.com", date: "Mar 16, 2026", total: 54.9, isPaid: true },
];
const usd = new Intl.NumberFormat("en", { style: "currency", currency: "USD" });
export default function Example() {
return (
<Table
aria-label="Orders"
rows={ORDERS}
columns={[
{ key: "id", header: "Order", isRowHeader: true },
{ key: "customer", header: "Customer", render: (order) => <Stack space="space-0"><Text truncate>{order.customer}</Text><Text size="body-small" tone="subtle" truncate><bdi>{order.email}</bdi></Text></Stack> },
{ key: "date", header: "Date", hideBelow: "sm" },
{ key: "isPaid", header: "Payment", render: (order) => (order.isPaid ? <Badge tone="success">Paid</Badge> : <Badge tone="warning">Pending</Badge>) },
{ key: "total", header: "Total", align: "end", render: (order) => usd.format(order.total) },
]}
/>
);
}import { Table } from "@senvenli/react/collection";Examples
Row selection
A checkbox per row and one in the header for the whole table.import { useState } from "react";
import { Table, type TableProps } from "@senvenli/react/collection";
import { Text } from "@senvenli/react/display";
import { Stack } from "@senvenli/react/layout";
type Product = { id: string; name: string; stock: number; price: number };
const PRODUCTS: Product[] = [
{ id: "chair", name: "Ergonomic chair", stock: 42, price: 349 },
{ id: "desk", name: "Standing desk, oak", stock: 17, price: 589 },
{ id: "arm", name: "Monitor arm, dual", stock: 63, price: 129 },
{ id: "lamp", name: "Desk lamp", stock: 0, price: 79 },
{ id: "tray", name: "Cable tray", stock: 118, price: 38 },
];
const usd = new Intl.NumberFormat("en", { style: "currency", currency: "USD", maximumFractionDigits: 0 });
// "all" once the header checkbox is pressed, a set of row ids otherwise.
type Keys = NonNullable<TableProps<Product>["selectedKeys"]>;
export default function Example() {
const [selected, setSelected] = useState<Keys>(new Set(["desk", "arm"]));
const count = selected === "all" ? PRODUCTS.length : [...selected].length;
return (
<Stack space="space-150">
<Table
aria-label="Products"
rows={PRODUCTS}
selectionMode="multiple"
selectedKeys={selected}
onSelectionChange={setSelected}
columns={[
{ key: "name", header: "Product" },
{ key: "stock", header: "In stock", align: "end" },
{ key: "price", header: "Price", align: "end", render: (product) => usd.format(product.price) },
]}
/>
<Text size="body-small" tone="subtle">{count} of {PRODUCTS.length} products selected</Text>
</Stack>
);
}Sortable columns
The table reports the sort; you sort the rows, here or on the server.import { useState } from "react";
import { Table, type TableProps } from "@senvenli/react/collection";
type Customer = { id: string; name: string; orders: number; spent: number };
const CUSTOMERS: Customer[] = [
{ id: "1", name: "Ada Lovelace", orders: 42, spent: 13020 },
{ id: "2", name: "Grace Hopper", orders: 18, spent: 11520 },
{ id: "3", name: "Alan Turing", orders: 64, spent: 6080 },
{ id: "4", name: "Katherine Johnson", orders: 27, spent: 4860 },
{ id: "5", name: "Margaret Hamilton", orders: 9, spent: 3780 },
];
const usd = new Intl.NumberFormat("en", { style: "currency", currency: "USD", maximumFractionDigits: 0 });
type Sort = NonNullable<TableProps<Customer>["sortDescriptor"]>;
export default function Example() {
const [sort, setSort] = useState<Sort>({ column: "spent", direction: "descending" });
const key = sort.column as keyof Customer;
const sign = sort.direction === "descending" ? -1 : 1;
const rows = [...CUSTOMERS].sort((a, b) => (a[key] < b[key] ? -1 : a[key] > b[key] ? 1 : 0) * sign);
return (
<Table
aria-label="Customers"
density="compact"
rows={rows}
sortDescriptor={sort}
onSortChange={setSort}
columns={[
{ key: "name", header: "Customer", isSortable: true },
{ key: "orders", header: "Orders", align: "end", isSortable: true },
{ key: "spent", header: "Total spent", align: "end", isSortable: true, render: (customer) => usd.format(customer.spent) },
]}
/>
);
}Guidelines
When to use it
- Records with several comparable fields on screens 640px and wider.
Use something else when
- The table also needs search, filters, paging or a column picker. Data table
- The screen is narrow or each record is one line of text. Grid list
Accessibility
Keyboard
| Keys | What happens |
|---|---|
| Arrow keys | Move between cells and rows. |
| Space | Selects the focused row. |
| Enter | Opens the focused row's record. |
Built in
- The row header column names each row for screen readers.
- Sort state is announced on the column header.
You provide
- An aria-label for the table.
API reference
Table
| Prop | Type | Default | Description |
|---|---|---|---|
aria-labelRequired | string | – | Names the table ("Orders"). |
columnsRequired | readonly TableColumn<T>[] | – | |
rowsRequired | readonly T[] | – | |
rowKey | (row: T) => Key | – | The row's stable id; |
selectionMode | "none" | "single" | "multiple" | – | |
selectedKeys | "all" | Iterable<Key> | – | |
defaultSelectedKeys | "all" | Iterable<Key> | – | |
onSelectionChange | (keys: Selection) => void | – | |
sortDescriptor | SortDescriptor | – | |
onSortChange | (descriptor: SortDescriptor) => void | – | |
density | Density | – |
|
emptyState | React.ReactNode | – | Shown when there are no rows: an |
onRowAction | (key: Key) => void | – | Opens the record: the whole row is the target. |
maxHeight | string | – | A height for the scroll area: the header stays put and gets a shadow once rows scroll under it. |
aria-labelRequiredstringNames the table ("Orders").
columnsRequiredreadonly TableColumn<T>[]rowsRequiredreadonly T[]rowKey(row: T) => KeyThe row's stable id;
row.idby default. Ids must be unique within the table. When the data has no single unique field, build one from the fields that are (${row.date}:${row.channel}), or add the row's index as a last resort. A repeated id still renders every row: the first keeps its id and the later ones are keyeda#2,a#3, … in row order, and selection andonRowActionreceive those suffixed keys; a development warning names the repeated ids. A suffixed key follows the row's position, not the row: after a sort or filter, a selection made through it can move to another copy of the id.selectionMode"none" | "single" | "multiple"selectedKeys"all" | Iterable<Key>defaultSelectedKeys"all" | Iterable<Key>onSelectionChange(keys: Selection) => voidsortDescriptorSortDescriptoronSortChange(descriptor: SortDescriptor) => voiddensityDensitycompact(36px rows) for dense working screens;default(48px) for public and content pages.emptyStateReact.ReactNodeShown when there are no rows: an
EmptyState, or one sentence on why it is empty and the action that fills it.onRowAction(key: Key) => voidOpens the record: the whole row is the target.
maxHeightstringA height for the scroll area: the header stays put and gets a shadow once rows scroll under it.