Components / Data

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.

DataTable · PlaygroundLive
Status
Date
240 rows
INV-0001Acme StudioPaid$120Jan 1, 2026
INV-0002Granite LabsOverdue$8,039Apr 12, 2026
INV-0003Bora TextilesPending$6,078Jul 23, 2026
INV-0004Iris CosmeticsPaid$4,117Oct 6, 2026
INV-0005Delta ArchitectsOverdue$2,156Mar 17, 2026
INV-0006Kite TravelPending$195Jun 28, 2026
INV-0007Fable BooksPaid$8,114Sep 11, 2026
INV-0008Atlas LogisticsOverdue$6,153Feb 22, 2026
INV-0009Harbor CoffeeOverdue$4,192May 5, 2026
INV-0010Cedar FoodsPending$2,231Aug 16, 2026
INV-0011Juniper HealthPaid$270Jan 27, 2026
INV-0012Echo RecordsOverdue$8,189Apr 10, 2026
INV-0013Acme StudioPending$6,228Jul 21, 2026
INV-0014Granite LabsPaid$4,267Oct 4, 2026
INV-0015Bora TextilesOverdue$2,306Mar 15, 2026
INV-0016Iris CosmeticsPending$345Jun 26, 2026
INV-0017Delta ArchitectsPending$8,264Sep 9, 2026
INV-0018Kite TravelPaid$6,303Feb 20, 2026
INV-0019Fable BooksOverdue$4,342May 3, 2026
JSX
<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:

TS
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 own options). Pair it with filterFn: "equalsString".
  • filter: { type: "dateRange" } adds a date range filter. Pair it with filterFn: "inDateRange".
  • label names the column in menus when the header isn't plain text.
Data Table · ColumnsLive
Status
Date
240 rows
INV-0001Acme StudioPaid$120Jan 1, 2026
INV-0002Granite LabsOverdue$8,039Apr 12, 2026
INV-0003Bora TextilesPending$6,078Jul 23, 2026
INV-0004Iris CosmeticsPaid$4,117Oct 6, 2026
INV-0005Delta ArchitectsOverdue$2,156Mar 17, 2026
INV-0006Kite TravelPending$195Jun 28, 2026
INV-0007Fable BooksPaid$8,114Sep 11, 2026
INV-0008Atlas LogisticsOverdue$6,153Feb 22, 2026
INV-0009Harbor CoffeeOverdue$4,192May 5, 2026
INV-0010Cedar FoodsPending$2,231Aug 16, 2026
INV-0011Juniper HealthPaid$270Jan 27, 2026
INV-0012Echo RecordsOverdue$8,189Apr 10, 2026
INV-0013Acme StudioPending$6,228Jul 21, 2026
INV-0014Granite LabsPaid$4,267Oct 4, 2026
INV-0015Bora TextilesOverdue$2,306Mar 15, 2026
INV-0016Iris CosmeticsPending$345Jun 26, 2026
INV-0017Delta ArchitectsPending$8,264Sep 9, 2026
INV-0018Kite TravelPaid$6,303Feb 20, 2026
INV-0019Fable BooksOverdue$4,342May 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().

Data Table · Bulk actionsLive
Status
Date
240 rows
INV-0001Acme StudioPaid$120Jan 1, 2026
INV-0002Granite LabsOverdue$8,039Apr 12, 2026
INV-0003Bora TextilesPending$6,078Jul 23, 2026
INV-0004Iris CosmeticsPaid$4,117Oct 6, 2026
INV-0005Delta ArchitectsOverdue$2,156Mar 17, 2026
INV-0006Kite TravelPending$195Jun 28, 2026
INV-0007Fable BooksPaid$8,114Sep 11, 2026
INV-0008Atlas LogisticsOverdue$6,153Feb 22, 2026
INV-0009Harbor CoffeeOverdue$4,192May 5, 2026
INV-0010Cedar FoodsPending$2,231Aug 16, 2026
INV-0011Juniper HealthPaid$270Jan 27, 2026
INV-0012Echo RecordsOverdue$8,189Apr 10, 2026
INV-0013Acme StudioPending$6,228Jul 21, 2026
INV-0014Granite LabsPaid$4,267Oct 4, 2026
INV-0015Bora TextilesOverdue$2,306Mar 15, 2026
INV-0016Iris CosmeticsPending$345Jun 26, 2026
INV-0017Delta ArchitectsPending$8,264Sep 9, 2026
INV-0018Kite TravelPaid$6,303Feb 20, 2026
INV-0019Fable BooksOverdue$4,342May 3, 2026
TSX
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.

Data Table · Server modeLive
Status
Date
0 rows
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.

Data Table · TurkishLive
8 kayıt
Zeynepİzmir
ÇağlaŞanlıurfa
ÖmerAnkara
IşılÇanakkale
İlkerIğdır
ŞuleBursa
CemOrdu
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 are columnheaders with aria-sort, and the sort buttons say which way they sort.
  • With virtual scrolling, aria-rowcount and aria-rowindex tell 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 have aria-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

PropTypeDefaultDescription
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.
selectablebooleanfalseCheckboxes 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.
bulkBarTapeboolean—Tape on the bulk bar. Defaults to the provider's tape setting.
searchablebooleantrueSearch field over every text column.
columnMenubooleantrueMenu to show and hide columns.
toolbarReactNode—Extra content at the end of the toolbar, like a “New” button.
heightstring | number"28rem"Height of the scrolling area. Virtualization needs a fixed height.
rowHeightnumber44Row height in pixels.
isLoadingbooleanfalseShows the loading state over the rows.
emptyStateReactNode—Content shown when there are no rows.
manualSortingboolean—Your server sorts: the table only reports sorting and shows the arrows.
manualFilteringboolean—Your server filters: the table only reports the search text and filters.
rowCountnumber—Total rows on the server, for the row counter.
sortingSortingState—Controlled sorting state, a list of { id, desc }.
onSortingChange(sorting: SortingState) => void—Called with the new sorting state.
globalFilterstring—Controlled search text.
onGlobalFilterChange(value: string) => void—Called as the search text changes.
columnFiltersColumnFiltersState—Controlled column filters.
onColumnFiltersChange(filters: ColumnFiltersState) => void—Called when a column filter changes.
rowSelectionRowSelectionState—Controlled selection, { [rowId]: true }.
onRowSelectionChange(selection: RowSelectionState) => void—Called when the selection changes.
columnVisibilityColumnVisibilityState—Controlled visible columns, { [columnId]: false } hides one.
onColumnVisibilityChange(visibility: ColumnVisibilityState) => void—Called when a column is shown or hidden.
messagesPartial<DataTableMessages>—Visible and screen reader texts, to translate the table. Pass only the ones you change.
aria-labelstring—Name of the table, for screen readers.
classNamestring—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.