DataTable
The grid of a data console: thousands of rows that scroll smoothly, columns you can sort, filter, resize and hide, rows to select and act on together, values edited in place, and CSV export. On a phone every row becomes a card, and long lists always paginate.
import { DataTable, DataTableSkeleton } from '@sypnia/ui/react'
10,000 rows
Scroll, sort by a column, open «Filters», hide columns or export what you see as CSV. The bar under the rows pages them: 100 at a time, or as many as you choose.
Code
import { useMemo } from 'react';
import { Badge, DataTable, useSypnia, type DataColumn } from '@sypnia/ui/react';
import { orders, statuses, type Order } from './data';
const tone = { Paid: 'ok', Pending: 'warn', Refunded: 'neutral', Failed: 'fail' } as const;
// 10,000 orders in the browser. Only the rows on screen are drawn, so it scrolls smoothly; the bar under the rows pages them.
// Sort by any column, filter by customer, status or country, show the hidden «Country» and «Items» columns, and export what you see as CSV.
export default function TenThousand() {
const { format } = useSypnia();
const rows = useMemo(() => orders(10000), []);
const columns: DataColumn<Order>[] = [
{ id: 'id', header: 'Order', machine: true, width: 120, value: (o) => o.id, sortable: true },
{ id: 'customer', header: 'Customer', width: 180, value: (o) => o.customer, sortable: true, filter: 'text' },
{ id: 'status', header: 'Status', width: 120, value: (o) => o.status, sortable: true, filter: 'select', options: statuses,
render: (o) => <Badge tone={tone[o.status as keyof typeof tone]} dot>{o.status}</Badge> },
{ id: 'country', header: 'Country', width: 150, value: (o) => o.country, sortable: true, filter: 'select',
options: ['Argentina', 'Chile', 'Colombia', 'Japan', 'Mexico', 'Peru', 'Spain', 'United States'] },
{ id: 'items', header: 'Items', numeric: true, width: 80, value: (o) => o.items, sortable: true },
{ id: 'placed', header: 'Placed', width: 120, value: (o) => o.placed, render: (o) => format.date(o.placed), sortable: true },
{ id: 'total', header: 'Total', numeric: true, width: 120, value: (o) => o.total, render: (o) => (o.total === null ? null : format.currency(o.total, 'USD')), sortable: true },
];
return <DataTable label="Orders" columns={columns} rows={rows} rowKey={(o) => o.id} columnPicker defaultHidden={['country', 'items']} exportName="orders" height="28rem" />;
} Edit in place
Double-click a value, or move to it and press Enter. Saving takes a moment. Try a negative price: it is refused, and the cell says why.
Code
import { useState } from 'react';
import { DataTable, type DataColumn } from '@sypnia/ui/react';
interface Plan { id: string; name: string; price: number; seats: number; status: string }
const start: Plan[] = [
{ id: 'starter', name: 'Starter', price: 9, seats: 3, status: 'Active' },
{ id: 'team', name: 'Team', price: 29, seats: 10, status: 'Active' },
{ id: 'business', name: 'Business', price: 99, seats: 50, status: 'Draft' },
{ id: 'legacy', name: 'Legacy 2024', price: 19, seats: 5, status: 'Archived' },
];
// Double-click a cell, or move to it and press Enter. Enter saves, Escape cancels, Tab saves and opens the next one.
// Saving takes a moment (the cell shows it is busy). A negative price is refused: the cell keeps what you typed and says why.
export default function Editable() {
const [plans, setPlans] = useState(start);
const save = (plan: Plan, column: string, value: unknown) => new Promise<void>((resolve, reject) => {
setTimeout(() => {
if (column === 'price' && Number(value) < 0) return reject(new Error('A price cannot be below zero.'));
setPlans((all) => all.map((p) => (p.id === plan.id ? { ...p, [column]: column === 'name' || column === 'status' ? value : Number(value) } : p)));
resolve();
}, 700);
});
const columns: DataColumn<Plan>[] = [
{ id: 'id', header: 'ID', machine: true, width: 120, value: (p) => p.id },
{ id: 'name', header: 'Name', width: 180, value: (p) => p.name, editable: true },
{ id: 'price', header: 'Price (USD)', numeric: true, width: 130, value: (p) => p.price, editable: true, editor: 'number' },
{ id: 'seats', header: 'Seats', numeric: true, width: 100, value: (p) => p.seats, editable: (p) => p.status !== 'Archived', editor: 'number' },
{ id: 'status', header: 'Status', width: 140, value: (p) => p.status, editable: true, editor: 'select', options: ['Active', 'Draft', 'Archived'] },
];
return <DataTable label="Plans" columns={columns} rows={plans} rowKey={(p) => p.id} onEdit={save} />;
} Select and act on many
Tick rows, or the header box to tick every row that matches the filters. The bar above the rows says how many and what can be done to all of them.
Code
import { useMemo, useState } from 'react';
import { Button, DataTable, type DataColumn, type RowKey } from '@sypnia/ui/react';
import { orders, type Order } from './data';
// Tick rows, or the box in the header to tick every row that matches the filters. A bar appears with what can be done to all of them.
export default function Selectable() {
const [rows, setRows] = useState(() => orders(240));
const [selected, setSelected] = useState<Set<RowKey>>(new Set());
const columns: DataColumn<Order>[] = useMemo(() => [
{ id: 'id', header: 'Order', machine: true, width: 130, value: (o) => o.id },
{ id: 'customer', header: 'Customer', width: 200, value: (o) => o.customer, filter: 'text' },
{ id: 'status', header: 'Status', width: 120, value: (o) => o.status, filter: 'select', options: ['Paid', 'Pending', 'Refunded', 'Failed'] },
{ id: 'total', header: 'Total', numeric: true, width: 120, value: (o) => o.total },
], []);
return (
<DataTable label="Orders to review" columns={columns} rows={rows} rowKey={(o) => o.id} pageSize={50} height="24rem"
selectable selected={selected} onSelect={setSelected}
bulkActions={(keys) => (
<>
<Button size="sm" icon="check" onClick={() => { setRows((all) => all.map((o) => (keys.includes(o.id) ? { ...o, status: 'Paid' } : o))); setSelected(new Set()); }}>Mark as paid</Button>
<Button size="sm" variant="danger" icon="trash" onClick={() => { setRows((all) => all.filter((o) => !keys.includes(o.id))); setSelected(new Set()); }}>Delete</Button>
</>
)} />
);
} As cards
What a phone shows, forced here with layout='cards': 25 cards a page, each value with its column name.
- ord_100080
- Customer
- Status
- Paid
- Total
- $364.69
- ord_100079
- Customer
- Status
- Paid
- Total
- $271.43
- ord_100078
- Customer
- Status
- Paid
- Total
- $187.12
- ord_100077
- Customer
- Status
- Pending
- Total
- $233.95
- ord_100076
- Customer
- Status
- Refunded
- Total
- $461.58
- ord_100075
- Customer
- Status
- Paid
- Total
- $454.17
- ord_100074
- Customer
- Status
- Paid
- Total
- $76.29
- ord_100073
- Customer
- Status
- Paid
- Total
- $278.69
- ord_100072
- Customer
- Status
- Pending
- Total
- $280.32
- ord_100071
- Customer
- Status
- Paid
- Total
- $27.44
- ord_100070
- Customer
- Status
- Paid
- Total
- $257.43
- ord_100069
- Customer
- Status
- Paid
- Total
- $211.98
- ord_100068
- Customer
- Status
- Paid
- Total
- $453.25
- ord_100067
- Customer
- Status
- Paid
- Total
- $258.12
- ord_100066
- Customer
- Status
- Paid
- Total
- $354.12
- ord_100065
- Customer
- Status
- Paid
- Total
- $195.72
- ord_100064
- Customer
- Status
- Pending
- Total
- $38.86
- ord_100063
- Customer
- Status
- Paid
- Total
- $110.00
- ord_100062
- Customer
- Status
- Paid
- Total
- $68.90
- ord_100061
- Customer
- Status
- Refunded
- Total
- $453.88
- ord_100060
- Customer
- Status
- Pending
- Total
- $38.02
- ord_100059
- Customer
- Status
- Paid
- Total
- $244.68
- ord_100058
- Customer
- Status
- Paid
- Total
- $186.97
- ord_100057
- Customer
- Status
- Refunded
- Total
- $456.50
- ord_100056
- Customer
- Status
- Paid
- Total
- $94.07
Code
import { useMemo } from 'react';
import { DataTable, useSypnia, type DataColumn } from '@sypnia/ui/react';
import { orders, type Order } from './data';
// On a phone (40rem and below) every row is a card, with no setting: the first column is the title and each value
// carries its column name. 25 cards a page. Here it is forced with layout="cards", so you can see it on any screen.
export default function Cards() {
const { format } = useSypnia();
const rows = useMemo(() => orders(80), []);
const columns: DataColumn<Order>[] = [
{ id: 'id', header: 'Order', machine: true, value: (o) => o.id },
{ id: 'customer', header: 'Customer', value: (o) => o.customer, editable: true },
{ id: 'status', header: 'Status', value: (o) => o.status },
{ id: 'total', header: 'Total', numeric: true, value: (o) => o.total, render: (o) => (o.total === null ? null : format.currency(o.total, 'USD')) },
];
return <DataTable layout="cards" label="Orders" columns={columns} rows={rows} rowKey={(o) => o.id} selectable onEdit={() => {}} />;
} Pages from a server
The table shows the page it was given, with skeleton rows while the next one comes, and reports the sort and the page.
Code
import { useEffect, useState } from 'react';
import { DataTable, type DataColumn, type DataSort } from '@sypnia/ui/react';
import { orders, type Order } from './data';
const all = orders(1342);
// A pretend server: it sorts and cuts the page, and answers after a moment.
function fetchPage(page: number, size: number, sort: DataSort | null) {
return new Promise<Order[]>((resolve) => setTimeout(() => {
const list = sort ? [...all].sort((a, b) => String(a[sort.id as keyof Order]).localeCompare(String(b[sort.id as keyof Order]), undefined, { numeric: true }) * (sort.dir === 'ascending' ? 1 : -1)) : all;
resolve(list.slice((page - 1) * size, page * size));
}, 600));
}
// When the rows live on a server, pass server and pagination: the table shows what it is given and reports the sort and the page.
export default function ServerPages() {
const [page, setPage] = useState(1);
const [size, setSize] = useState(25);
const [sort, setSort] = useState<DataSort | null>(null);
const [rows, setRows] = useState<Order[] | undefined>();
useEffect(() => { let live = true; setRows(undefined); fetchPage(page, size, sort).then((r) => live && setRows(r)); return () => { live = false; }; }, [page, size, sort]);
const columns: DataColumn<Order>[] = [
{ id: 'id', header: 'Order', machine: true, width: 130, value: (o) => o.id, sortable: true },
{ id: 'customer', header: 'Customer', width: 200, value: (o) => o.customer, sortable: true },
{ id: 'placed', header: 'Placed', width: 130, value: (o) => o.placed, sortable: true },
{ id: 'total', header: 'Total', numeric: true, width: 120, value: (o) => o.total, sortable: true },
];
return (
<DataTable server label="Orders" columns={columns} rows={rows} loading={!rows} rowKey={(o) => o.id} height="22rem"
sort={sort} onSort={(s) => { setSort(s); setPage(1); }}
pagination={{ page, pageSize: size, total: all.length, onPage: setPage, onPageSize: (n) => { setSize(n); setPage(1); } }} />
);
} Loading, error and empty
Choose a state. «Try again» and «Create a key» take you to the rows.
Code
import { useState } from 'react';
import { Button, DataTable, EmptyState, SegmentedControl, type DataColumn } from '@sypnia/ui/react';
interface Key { id: string; name: string; created: string }
const columns: DataColumn<Key>[] = [
{ id: 'name', header: 'Name', value: (k) => k.name },
{ id: 'id', header: 'Key', machine: true, value: (k) => k.id },
{ id: 'created', header: 'Created', value: (k) => k.created },
];
const keys: Key[] = [{ id: 'sk_live_4f1a…9c2e', name: 'Back office', created: '2026-11-02' }];
// Loading draws skeleton rows with the real columns, never a spinner. An error says what happened and offers to try again.
// An empty table says what goes in it and the first step.
export default function States() {
const [state, setState] = useState('loading');
return (
<div className="sy-stack">
<SegmentedControl label="State" value={state} onChange={setState}
options={[{ value: 'loading', label: 'Loading' }, { value: 'error', label: 'Error' }, { value: 'empty', label: 'Empty' }, { value: 'ready', label: 'Ready' }]} />
<DataTable label="API keys" columns={columns} rowKey={(k) => k.id}
rows={state === 'ready' ? keys : state === 'empty' ? [] : undefined} loading={state === 'loading'}
error={state === 'error' ? 'The keys could not be loaded. The server did not answer in time.' : undefined} onRetry={() => setState('ready')}
empty={<EmptyState icon="key" title="No keys yet" actions={<Button variant="primary" icon="plus" onClick={() => setState('ready')}>Create a key</Button>}>A key lets your server talk to Sypnia without a password.</EmptyState>} />
</div>
);
} Skeleton
Before even the columns are known: the same boxes as the real one, so nothing moves when the data arrives. On a phone, cards.
Code
import { DataTableSkeleton } from '@sypnia/ui/react';
// Before even the columns are known: toolbar, header, rows and the pagination bar on wide screens, and cards on phones,
// in the same boxes as a real DataTable. When the columns are known, use <DataTable loading> instead.
export default function Skeleton() {
return <DataTableSkeleton columns={5} rows={6} selectable />;
} When to use it
Use it when
- People work with the rows, not just read them: they look for some, change values, act on many at once.
- There are hundreds or thousands of rows: only the ones on screen are drawn.
- Rows live on a server: pass
serverandpagination, and the table reports the sort, the filters and the page. - Give every column a
value: it is what sorts, filters, edits and goes to the CSV.renderonly changes how it looks.
Do not use it when
- People only read a few rows: Table is lighter and enough.
- It is facts about a single thing: KeyValue.
- Each item has a different shape or a picture: Cards.
For everyone
- It is a grid with a name (
label) and a single tab stop. Arrow keys move between cells, Home and End go to the ends of a row, Page Up and Page Down move a screen at a time. - Enter edits the cell, Enter or Tab saves it, Escape cancels. While it saves the cell is marked busy; if the save fails it keeps what was typed and says why.
- A sortable header is a button named «Sort by Total», and the column says how it is sorted. A column edge can be resized with the arrow keys.
- Empty values are written NULL, so «nothing» never looks like an empty string.
- Loading draws skeleton rows with the real columns, never a spinner. The count of rows and selected rows is announced.
- On phones (40rem and below) each row is a card: every value carries its column name, and the checkbox and the edit buttons are at least 44 px.
Props
| DataTable | Type | Default |
|---|---|---|
columnsrequired | DataColumn<Row>[] | |
labelrequiredA name for screen readers. | string | |
rowKeyrequired | (row: Row) => RowKey | |
rowsrequiredThe rows in memory: all of them (the table scrolls through thousands), or one page when `pagination` is set. | Row[] | undefined | |
bulkActionsButtons for the bar that appears while rows are selected. Receives the selected keys and the selected rows that are in memory. | ((keys: RowKey[], rows: Row[]) => ReactNode) | |
columnPickerAdds the «Columns» menu to the toolbar. | boolean | |
defaultHiddenIds of columns hidden at first. With `columnPicker` the person can change them. | string[] | |
defaultSort | DataSort | null | null |
emptyWhat to show when there are no rows at all: an EmptyState with the next step. | ReactNode | |
errorSomething failed: say what happened in plain words. | ReactNode | |
exportNameAdds «Export CSV» to the toolbar. This is the name of the file. It exports the selected rows, or all the rows shown. | string | |
filtersControlled filters, by column id. Leave it out and the table keeps its own. | DataFilters | |
heightThe tallest the grid gets before it scrolls: any CSS length. | string | min(32rem, 70dvh) |
layout`auto`: a grid on wide screens, cards on phones. Force one of them for a narrow panel or a preview. | "grid" | "cards" | "auto" | auto |
loadingData is on its way: rows are drawn as skeletons of the right shape. | boolean | |
loadingRowsHow many skeleton rows (cards on phones) to draw while loading: as many as will come. Default 8 rows, 3 cards. Or the rows of the last visit: as many, and on phones each card's values that can be edited wait in their edit box (an `editable` function is asked about each of them). | number | Row[] | |
onColumnWidthsCalled with every width, by column id, after the person resizes one. | ((widths: Record<string, number>) => void) | |
onEditSaves one value. Return a promise and the cell shows it is busy; reject it (or throw) and the cell keeps what was typed and shows the reason. | ((row: Row, columnId: string, value: unknown) => void | Promise<unknown>) | |
onFilter | ((filters: DataFilters) => void) | |
onRetryWith `error`: shows «Try again». | (() => void) | |
onSelect | ((selected: Set<RowKey>) => void) | |
onSort | ((sort: DataSort | null) => void) | |
pageSizeRows in memory are shown a page at a time (every table paginates). The person can change it. On phones a page holds at most 25 cards. | number | 100 |
pageSizesThe page sizes the person can choose from. | number[] | [50, 100, 250, 500] |
paginationServer pages: the table shows `rows` as one page and this bar under them. Without it the table pages the rows in memory itself (`pageSize`). | { page: number; pageSize: number; total: number; onPage: (page: number) => void; onPageSize?: ((size: number) => void); } | |
selectableAdds a checkbox to every row. | boolean | |
selectedControlled selection: the keys of the selected rows. | ReadonlySet<RowKey> | |
serverThe rows already arrive sorted and filtered (by a server): the table only reports what the person asked through `onSort` and `onFilter`. | boolean | |
sortControlled sort. Leave it out and the table keeps its own. | DataSort | null | |
toolbarExtra content at the start of the toolbar: a search field, a title. | ReactNode |
| DataTableSkeleton | Type | Default |
|---|---|---|
columns | number | 5 |
layout | "grid" | "cards" | "auto" | auto |
pagination | boolean | true |
rows | number | 8 |
selectable | boolean | |
toolbar | boolean | true |