Data Table09
Sorting, search, filters, column controls, bulk selection and virtual scrolling for thousands of rows. Rows don't just jump when you sort: they fly to their new place, hop in Comic and step in Arcade.
| INV-0001 | Acme Studio | Paid | $120 | Jan 1, 2026 |
| INV-0002 | Granite Labs | Overdue | $8,039 | Apr 12, 2026 |
| INV-0003 | Bora Textiles | Pending | $6,078 | Jul 23, 2026 |
| INV-0004 | Iris Cosmetics | Paid | $4,117 | Oct 6, 2026 |
| INV-0005 | Delta Architects | Overdue | $2,156 | Mar 17, 2026 |
| INV-0006 | Kite Travel | Pending | $195 | Jun 28, 2026 |
| INV-0007 | Fable Books | Paid | $8,114 | Sep 11, 2026 |
| INV-0008 | Atlas Logistics | Overdue | $6,153 | Feb 22, 2026 |
| INV-0009 | Harbor Coffee | Overdue | $4,192 | May 5, 2026 |
| INV-0010 | Cedar Foods | Pending | $2,231 | Aug 16, 2026 |
| INV-0011 | Juniper Health | Paid | $270 | Jan 27, 2026 |
| INV-0012 | Echo Records | Overdue | $8,189 | Apr 10, 2026 |
| INV-0013 | Acme Studio | Pending | $6,228 | Jul 21, 2026 |
| INV-0014 | Granite Labs | Paid | $4,267 | Oct 4, 2026 |
| INV-0015 | Bora Textiles | Overdue | $2,306 | Mar 15, 2026 |
| INV-0016 | Iris Cosmetics | Pending | $345 | Jun 26, 2026 |
| INV-0017 | Delta Architects | Pending | $8,264 | Sep 9, 2026 |
| INV-0018 | Kite Travel | Paid | $6,303 | Feb 20, 2026 |
| INV-0019 | Fable Books | Overdue | $4,342 | May 3, 2026 |
<DataTable
aria-label="Invoices"
data={invoices}
columns={columns}
getRowId={(row) => row.id}
height="24rem"
/>Usage
import { DataTable } from "plonk-ui";
import { columns } from "./columns";
export function Invoices({ invoices }: { invoices: Invoice[] }) {
return (
<DataTable
aria-label="Invoices"
data={invoices}
columns={columns}
getRowId={(row) => row.id}
/>
);
}DataTable is built on TanStack Table and
TanStack Virtual. getRowId gives every row a stable id: selection and the
reorder animation follow it, even when the data changes.
The examples use 240 sample invoices:
interface Invoice {
id: string; // "INV-0001"
customer: string;
status: "Paid" | "Pending" | "Overdue";
amount: number;
date: Date;
}Columns
Define columns with createDataTableColumns<Row>(). Each accessor reads a
field, header names it and cell renders it. Plonk's own settings live in
meta:
align: "end"right-aligns numbers and dates.filter: { type: "select" }adds a filter to the toolbar with the column's values (or your ownoptions). Pair it withfilterFn: "equalsString".filter: { type: "dateRange" }adds a date range filter. Pair it withfilterFn: "inDateRange".labelnames the column in menus when the header isn't plain text.
| INV-0001 | Acme Studio | Paid | $120 | Jan 1, 2026 |
| INV-0002 | Granite Labs | Overdue | $8,039 | Apr 12, 2026 |
| INV-0003 | Bora Textiles | Pending | $6,078 | Jul 23, 2026 |
| INV-0004 | Iris Cosmetics | Paid | $4,117 | Oct 6, 2026 |
| INV-0005 | Delta Architects | Overdue | $2,156 | Mar 17, 2026 |
| INV-0006 | Kite Travel | Pending | $195 | Jun 28, 2026 |
| INV-0007 | Fable Books | Paid | $8,114 | Sep 11, 2026 |
| INV-0008 | Atlas Logistics | Overdue | $6,153 | Feb 22, 2026 |
| INV-0009 | Harbor Coffee | Overdue | $4,192 | May 5, 2026 |
| INV-0010 | Cedar Foods | Pending | $2,231 | Aug 16, 2026 |
| INV-0011 | Juniper Health | Paid | $270 | Jan 27, 2026 |
| INV-0012 | Echo Records | Overdue | $8,189 | Apr 10, 2026 |
| INV-0013 | Acme Studio | Pending | $6,228 | Jul 21, 2026 |
| INV-0014 | Granite Labs | Paid | $4,267 | Oct 4, 2026 |
| INV-0015 | Bora Textiles | Overdue | $2,306 | Mar 15, 2026 |
| INV-0016 | Iris Cosmetics | Pending | $345 | Jun 26, 2026 |
| INV-0017 | Delta Architects | Pending | $8,264 | Sep 9, 2026 |
| INV-0018 | Kite Travel | Paid | $6,303 | Feb 20, 2026 |
| INV-0019 | Fable Books | Overdue | $4,342 | May 3, 2026 |
import { Badge, DataTable, createDataTableColumns } from "plonk-ui";
import { INVOICES, type Invoice } from "./invoices";
const money = new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
maximumFractionDigits: 0,
});
const day = new Intl.DateTimeFormat("en-US", { dateStyle: "medium" });
const STATUS_VARIANT = {
Paid: "success",
Pending: "warning",
Overdue: "danger",
} as const;
const col = createDataTableColumns<Invoice>();
export const COLUMNS = col.columns([
col.accessor("id", { header: "Invoice", size: 110 }),
col.accessor("customer", { header: "Customer", size: 190 }),
col.accessor("status", {
header: "Status",
size: 130,
filterFn: "equalsString",
meta: { filter: { type: "select" } },
cell: (info) => (
<Badge variant={STATUS_VARIANT[info.getValue()]}>{info.getValue()}</Badge>
),
}),
col.accessor("amount", {
header: "Amount",
size: 130,
meta: { align: "end" },
cell: (info) => money.format(info.getValue()),
}),
col.accessor("date", {
header: "Date",
size: 130,
filterFn: "inDateRange",
enableGlobalFilter: false,
meta: { align: "end", filter: { type: "dateRange" } },
cell: (info) => day.format(info.getValue()),
}),
]);
export default function Columns() {
return (
<DataTable
aria-label="Invoices"
data={INVOICES}
columns={COLUMNS}
getRowId={(row) => row.id}
height="24rem"
className="w-full"
/>
);
}Drag a header's edge to resize a column. The column menu shows and hides columns.
Sorting
Click a header to sort: ascending, then descending, then back to unsorted.
Text sorts by the provider's locale, so "Çınar" comes after "Cedar", not
after "Zeytin".
Shift + click another header to sort by several columns at once. The headers show their order, 1 and 2: try Status, then Shift + Amount.
Selection and bulk actions
selectable adds a checkbox to each row. While rows are selected, a bar
appears with the count and your bulkActions, which get the selected rows,
their ids and clear().
| INV-0001 | Acme Studio | Paid | $120 | Jan 1, 2026 | |
| INV-0002 | Granite Labs | Overdue | $8,039 | Apr 12, 2026 | |
| INV-0003 | Bora Textiles | Pending | $6,078 | Jul 23, 2026 | |
| INV-0004 | Iris Cosmetics | Paid | $4,117 | Oct 6, 2026 | |
| INV-0005 | Delta Architects | Overdue | $2,156 | Mar 17, 2026 | |
| INV-0006 | Kite Travel | Pending | $195 | Jun 28, 2026 | |
| INV-0007 | Fable Books | Paid | $8,114 | Sep 11, 2026 | |
| INV-0008 | Atlas Logistics | Overdue | $6,153 | Feb 22, 2026 | |
| INV-0009 | Harbor Coffee | Overdue | $4,192 | May 5, 2026 | |
| INV-0010 | Cedar Foods | Pending | $2,231 | Aug 16, 2026 | |
| INV-0011 | Juniper Health | Paid | $270 | Jan 27, 2026 | |
| INV-0012 | Echo Records | Overdue | $8,189 | Apr 10, 2026 | |
| INV-0013 | Acme Studio | Pending | $6,228 | Jul 21, 2026 | |
| INV-0014 | Granite Labs | Paid | $4,267 | Oct 4, 2026 | |
| INV-0015 | Bora Textiles | Overdue | $2,306 | Mar 15, 2026 | |
| INV-0016 | Iris Cosmetics | Pending | $345 | Jun 26, 2026 | |
| INV-0017 | Delta Architects | Pending | $8,264 | Sep 9, 2026 | |
| INV-0018 | Kite Travel | Paid | $6,303 | Feb 20, 2026 | |
| INV-0019 | Fable Books | Overdue | $4,342 | May 3, 2026 |
import { useState } from "react";
import { Button, DataTable } from "plonk-ui";
import { COLUMNS } from "./columns";
import { INVOICES } from "./invoices";
export default function Bulk() {
const [rows, setRows] = useState(INVOICES);
return (
<DataTable
aria-label="Invoices"
data={rows}
columns={COLUMNS}
getRowId={(row) => row.id}
height="24rem"
className="w-full"
selectable
toolbar={
<Button size="sm" variant="ghost" onPress={() => setRows(INVOICES)}>
Reset
</Button>
}
bulkActions={({ ids, clear }) => (
<>
<Button
size="sm"
variant="neutral"
onPress={() => {
const picked = new Set(ids);
setRows((all) =>
all.map((r) =>
picked.has(r.id) ? { ...r, status: "Paid" } : r,
),
);
clear();
}}
>
Mark paid
</Button>
<Button
size="sm"
variant="danger"
onPress={() => {
const picked = new Set(ids);
setRows((all) => all.filter((r) => !picked.has(r.id)));
clear();
}}
>
Delete
</Button>
</>
)}
/>
);
}Shift + click a checkbox to select every row between it and the last one you clicked. The header checkbox selects all rows that match the current search and filters.
Rows that leave the data drop out of the selection on their own. The bar's tape
follows the provider's tape setting; bulkBarTape overrides it.
Search and filters
The search field matches every text column, lowercasing by the provider's
locale ("ışık" finds "Işık"). Turn it off with searchable={false}, or
exclude a column with enableGlobalFilter: false, as the date column does.
Large data and height
Only the rows on screen are drawn, so thousands of rows scroll smoothly. That
needs a fixed height (28rem by default) and a fixed rowHeight (44px).
Server mode
When your server sorts and searches, set manualSorting and
manualFiltering. The table stops doing it itself and reports what the user
asked for through the controlled props; you fetch and pass the new data.
rowCount keeps the counter honest and isLoading shows the wait.
import { useEffect, useState } from "react";
import { DataTable, type SortingState } from "plonk-ui";
import { COLUMNS } from "./columns";
import { INVOICES, type Invoice } from "./invoices";
// Stands in for your API: sorts and searches on the "server", then answers.
async function fetchInvoices(sorting: SortingState, search: string) {
await new Promise((resolve) => setTimeout(resolve, 500));
const query = search.toLowerCase();
const rows = INVOICES.filter(
(r) => !query || `${r.id} ${r.customer}`.toLowerCase().includes(query),
);
const [sort] = sorting;
if (sort) {
const key = sort.id as keyof Invoice;
rows.sort((a, b) => (a[key] < b[key] ? -1 : a[key] > b[key] ? 1 : 0));
if (sort.desc) rows.reverse();
}
return { rows, total: INVOICES.length };
}
export default function Server() {
const [sorting, setSorting] = useState<SortingState>([]);
const [search, setSearch] = useState("");
const [result, setResult] = useState<{
request: string;
rows: Invoice[];
total: number;
}>();
// Loading until the answer for the current request arrives.
const request = JSON.stringify([sorting, search]);
const loading = result?.request !== request;
useEffect(() => {
let current = true;
fetchInvoices(sorting, search).then((next) => {
if (current) setResult({ request, ...next });
});
return () => {
current = false;
};
}, [request, sorting, search]);
return (
<DataTable
aria-label="Invoices"
data={result?.rows ?? []}
columns={COLUMNS}
getRowId={(row) => row.id}
height="24rem"
className="w-full"
columnMenu={false}
manualSorting
manualFiltering
sorting={sorting}
onSortingChange={setSorting}
globalFilter={search}
onGlobalFilterChange={setSearch}
rowCount={result?.total}
isLoading={loading}
/>
);
}Every piece of state has a controlled pair: sorting, globalFilter,
columnFilters, rowSelection and columnVisibility, each with its
on…Change. Use them to keep the table's state in the URL, too.
Localization
messages translates every visible and screen reader text; pass only the ones
you change. With <PlonkProvider locale="tr-TR">, as in this example, sorting
and search follow Turkish rules: Ç after C, Ş after S, and İ and I are
different letters.
| Zeynep | İzmir |
| Çağla | Şanlıurfa |
| Ömer | Ankara |
| Işıl | Çanakkale |
| İlker | Iğdır |
| Şule | Bursa |
| Cem | Ordu |
| Sevgi | Üsküdar |
import { DataTable, createDataTableColumns } from "plonk-ui";
interface Customer {
name: string;
city: string;
}
const CUSTOMERS: Customer[] = [
{ name: "Zeynep", city: "İzmir" },
{ name: "Çağla", city: "Şanlıurfa" },
{ name: "Ömer", city: "Ankara" },
{ name: "Işıl", city: "Çanakkale" },
{ name: "İlker", city: "Iğdır" },
{ name: "Şule", city: "Bursa" },
{ name: "Cem", city: "Ordu" },
{ name: "Sevgi", city: "Üsküdar" },
];
const col = createDataTableColumns<Customer>();
const COLUMNS = col.columns([
col.accessor("name", { header: "Ad", size: 140 }),
col.accessor("city", { header: "Şehir", size: 160 }),
]);
const MESSAGES = {
search: "Ara…",
columns: "Sütunlar",
all: "Tümü",
clearFilters: "Filtreleri temizle",
noResults: "Eşleşen kayıt yok",
loading: "Yükleniyor…",
selected: "seçili",
clearSelection: "Seçimi temizle",
selectAll: "Tümünü seç",
selectRow: "Satırı seç",
rowCount: (shown: number, total: number) =>
shown === total ? `${total} kayıt` : `${shown} / ${total} kayıt`,
};
export default function Turkish() {
return (
<DataTable
aria-label="Müşteriler"
data={CUSTOMERS}
columns={COLUMNS}
getRowId={(row) => row.name}
height="20rem"
className="w-full"
messages={MESSAGES}
/>
);
}Personalities
- Sticker: sorted rows fly to their place, leaning on the way and squashing when they land; selected rows are swept with a highlighter, and the bulk bar is taped down.
- Retro: rows move in steps and selections are dithered.
- Comic: a yellow header strip; rows hop to their place and new ones pop in; selected rows get blue halftone and the bulk bar is a speech bubble.
- Arcade: "high score" headers, alternating rows, neon selection, rows that step into place, and a neon bulk bar with a ticking count.
With reduced motion, rows fade into their new order.
Accessibility
- A real
<table>: headers arecolumnheaders witharia-sort, and the sort buttons say which way they sort. - With virtual scrolling,
aria-rowcountandaria-rowindextell screen readers the full size of the table and where each row is. - Checkboxes are named "Select row" and "Select all rows" (translate them in
messages); selected rows havearia-selected. - The bulk bar is a toolbar named by the selection count, and the count is announced as it changes.
- The search field, filters and column menu are reachable with
Tab.
API
| Prop | Type | Default | Description |
|---|---|---|---|
data* | T[] | — | Rows to show. Thousands are fine: rows are virtualized. |
columns* | DataTableColumn<T>[] | — | Column definitions from createDataTableColumns<Row>(). |
getRowId* | (row: T) => string | — | A stable id for each row. Selection and the reorder animation follow it. |
selectable | boolean | false | Checkboxes at the start of each row and a bar of bulk actions while rows are selected. |
bulkActions | (ctx: DataTableBulkContext<T>) => ReactNode | — | Buttons in the bulk bar. Gets { rows, ids, clear } for the selection. |
bulkBarTape | boolean | — | Tape on the bulk bar. Defaults to the provider's tape setting. |
searchable | boolean | true | Search field over every text column. |
columnMenu | boolean | true | Menu to show and hide columns. |
toolbar | ReactNode | — | Extra content at the end of the toolbar, like a “New” button. |
height | string | number | "28rem" | Height of the scrolling area. Virtualization needs a fixed height. |
rowHeight | number | 44 | Row height in pixels. |
isLoading | boolean | false | Shows the loading state over the rows. |
emptyState | ReactNode | — | Content shown when there are no rows. |
manualSorting | boolean | — | Your server sorts: the table only reports sorting and shows the arrows. |
manualFiltering | boolean | — | Your server filters: the table only reports the search text and filters. |
rowCount | number | — | Total rows on the server, for the row counter. |
sorting | SortingState | — | Controlled sorting state, a list of { id, desc }. |
onSortingChange | (sorting: SortingState) => void | — | Called with the new sorting state. |
globalFilter | string | — | Controlled search text. |
onGlobalFilterChange | (value: string) => void | — | Called as the search text changes. |
columnFilters | ColumnFiltersState | — | Controlled column filters. |
onColumnFiltersChange | (filters: ColumnFiltersState) => void | — | Called when a column filter changes. |
rowSelection | RowSelectionState | — | Controlled selection, { [rowId]: true }. |
onRowSelectionChange | (selection: RowSelectionState) => void | — | Called when the selection changes. |
columnVisibility | ColumnVisibilityState | — | Controlled visible columns, { [columnId]: false } hides one. |
onColumnVisibilityChange | (visibility: ColumnVisibilityState) => void | — | Called when a column is shown or hidden. |
messages | Partial<DataTableMessages> | — | Visible and screen reader texts, to translate the table. Pass only the ones you change. |
aria-label | string | — | Name of the table, for screen readers. |
className | string | — | Extra classes for the outer wrapper. |
The column helper, createDataTableColumns<Row>(), is TanStack Table's column
helper with Plonk's features registered; see TanStack's docs for every column
option.