React Data Table
A typed, accessible React data table on TanStack Table v9 with search, faceted filters, multi-sort, pagination, selection and CSV export, all in glass.
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/data-table.jsonDataTableUserCellHighlightStatusCellCurrencyCell- +10 more
- +7 more
Files to copy
17 folders · 25 files · 5 packages
- From
theme/src/ components/data-table/components/pagination/components/alert/components/avatar/components/badge/components/button/components/checkbox/components/drawer/parts/sheet.tsxcomponents/input/components/progress/components/select/components/spinner/components/status-icons/hooks/{use-controllable.ts, use-direction.ts, use-latest.ts, use-magnetic.ts, use-media-query.ts, use-preferences.ts, use-virtual-window.ts}motion/{gate.ts, reorder.tsx, tokens.ts}lib/{cn.ts, csv.ts, field-control-shell.tsx, field-size.ts, form.ts, glide-highlight.tsx, group-segments.ts, initials.ts, motion-props.ts, page-size.ts, popup-a11y.ts, popup-motion.ts, state-light.tsx, warn-once.ts}styles/
- shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/data-table.jsonRegistry item: data-table. The styles need the Tailwind v4 glass UI setup.- Packages
pnpm add @base-ui/react @tanstack/react-table clsx motion tailwind-merge
Full-featured (client-side)
312 generated users. Search highlights matches, filters show counts, shift-click headers to sort by several columns, shift-click checkboxes to select a range. Selection survives paging. Under 640px the rows become cards.
Showing 1–10 of 312
import { CurrencyCell, ProgressCell, RelativeDateCell, StatusCell, UserCell } from "@/components/sheenui/data-table/cells";
import { DataTable } from "@/components/sheenui/data-table/data-table";
import { type DataTableColumn, type DataTableFilterOption } from "@/components/sheenui/data-table/types";
// Package build (after the first npm release, or a packed tarball): import { CurrencyCell, DataTable, type DataTableColumn, ProgressCell, RelativeDateCell, StatusCell, UserCell, type DataTableFilterOption } from "@sheenui/theme";
import { Pencil as EditIcon, Eye as EyeIcon, Trash2 as TrashIcon } from "lucide-react";
type User = {
id: string;
name: string;
email: string;
role: "Owner" | "Admin" | "Editor" | "Viewer" | "Billing";
status: "active" | "trial" | "past_due" | "churned" | "invited";
mrr: number;
signedUp: string; // ISO date
usage: number; // 0 to 100
country: string;
};
// Your data: rows from an API or a store (a few inline here so the example runs as pasted).
const users: User[] = [
{ id: "u1", name: "Ravi Kumar", email: "ravi@example.com", role: "Owner", status: "active", mrr: 240, signedUp: "2025-01-14", usage: 82, country: "IN" },
{ id: "u2", name: "Asha Patel", email: "asha@example.com", role: "Admin", status: "trial", mrr: 0, signedUp: "2025-06-02", usage: 35, country: "GB" },
{ id: "u3", name: "Meera Shah", email: "meera@example.com", role: "Editor", status: "past_due", mrr: 90, signedUp: "2024-11-23", usage: 58, country: "US" },
{ id: "u4", name: "Kabir Rao", email: "kabir@example.com", role: "Viewer", status: "invited", mrr: 0, signedUp: "2025-08-30", usage: 4, country: "DE" },
];
const roleOptions: DataTableFilterOption[] = ["Owner", "Admin", "Editor", "Viewer", "Billing"].map((role) => ({ value: role, label: role }));
const statusOptions: DataTableFilterOption[] = ["active", "trial", "past_due", "churned", "invited"].map((status) => ({ value: status, label: status }));
export function Example() {
const columns: DataTableColumn<User>[] = [
{
id: "name", header: "User", minWidth: 240,
searchValue: (u) => `${u.name} ${u.email}`,
cell: ({ row, highlight }) => <UserCell name={row.name} email={row.email} highlight={highlight} />,
},
{ id: "role", header: "Role", filter: "faceted", filterOptions: roleOptions },
{
id: "status", header: "Status", filter: "faceted", filterOptions: statusOptions,
cell: ({ row }) => <StatusCell value={row.status} tones={{ active: "success", churned: "danger" }} />,
},
{ id: "mrr", header: "MRR", numeric: true, cell: ({ row }) => <CurrencyCell value={row.mrr} locale="en-US" /> },
{ id: "signedUp", header: "Signed up", sortFn: "datetime", cell: ({ row }) => <RelativeDateCell value={row.signedUp} now={Date.now()} locale="en-US" /> },
{ id: "usage", header: "Usage", numeric: true, cell: ({ row }) => <ProgressCell value={row.usage} label="Usage" /> },
{ id: "country", header: "Country", defaultHidden: true },
];
return (
<DataTable
caption="Workspace members"
data={users}
columns={columns}
enableSelection
mobileLayout="cards"
maxHeight="36rem"
rowActions={[
{ label: "View", icon: <EyeIcon />, onSelect: (u) => console.log("view", u.id) },
{ label: "Edit", icon: <EditIcon />, onSelect: (u) => console.log("edit", u.id) },
{ label: "Delete", icon: <TrashIcon />, tone: "danger", separatorBefore: true, onSelect: (u) => console.log("delete", u.id) },
]}
bulkActions={[
{ label: "Delete", tone: "danger", icon: <TrashIcon />, onSelect: (rows, clear) => {
console.log("delete", rows.length, "users");
clear();
} },
]}
renderExpanded={(u) => (
<p className="p-4 text-sm">
{u.name} · {u.country} · {u.email}
</p>
)}
/>
);
}Server-side
manual + rowCount: the table only renders. Sorting, search (debounced), filters and paging go to a fake API that answers after 600ms. While it loads, the previous rows stay in place under a veil, so nothing jumps.
import { useState } from "react";
import { DataTable } from "@/components/sheenui/data-table/data-table";
import { type DataTableColumn, type DataTableColumnFilters, type DataTableSorting } from "@/components/sheenui/data-table/types";
// Package build (after the first npm release, or a packed tarball): import { DataTable, type DataTableColumn, type DataTableColumnFilters, type DataTableSorting } from "@sheenui/theme";
type Customer = { id: string; name: string; plan: string; mrr: number };
const columns: DataTableColumn<Customer>[] = [
{ id: "name", header: "Customer" },
{ id: "plan", header: "Plan" },
{ id: "mrr", header: "MRR", numeric: true },
];
// Sketch (the hook is yours to write, so this is not runnable as pasted): sends sorting, pagination, search and filters to the server (TanStack Query, SWR or your own).
declare function useUsers(query: {
sorting: DataTableSorting;
pagination: { pageIndex: number; pageSize: number };
search: string;
filters: DataTableColumnFilters;
}): { data: Customer[]; total: number; isFetching: boolean; error?: Error; refetch: () => void };
export function Example() {
const [sorting, setSorting] = useState<DataTableSorting>([]);
const [pagination, setPagination] = useState({ pageIndex: 0, pageSize: 10 });
const [search, setSearch] = useState("");
const [filters, setFilters] = useState<DataTableColumnFilters>([]);
const { data, total, isFetching, error, refetch } = useUsers({ sorting, pagination, search, filters });
return (
<DataTable
caption="Customers (server)"
manual
rowCount={total}
data={data}
columns={columns}
loading={isFetching}
error={error?.message}
onRetry={refetch}
sorting={sorting} onSortingChange={setSorting}
pagination={pagination} onPaginationChange={setPagination}
globalFilter={search} onGlobalFilterChange={setSearch}
columnFilters={filters} onColumnFiltersChange={setFilters}
/>
);
}Minimal
Just data, columns and a caption. Search, sorting, export and the View menu come with sensible defaults; turn any of them off with a prop.
import { formatCurrency } from "@/components/sheenui/data-table/cells";
import { DataTable } from "@/components/sheenui/data-table/data-table";
import { type DataTableColumn } from "@/components/sheenui/data-table/types";
// Package build (after the first npm release, or a packed tarball): import { DataTable, type DataTableColumn, formatCurrency } from "@sheenui/theme";
type Invoice = { id: string; customer: string; due: string; amount: number };
const invoices: Invoice[] = [
{ id: "INV-1001", customer: "Acme Corp", due: "Nov 30", amount: 1280 },
{ id: "INV-1002", customer: "Globex", due: "Dec 04", amount: 640.5 },
{ id: "INV-1003", customer: "Initech", due: "Dec 12", amount: 2210 },
];
export function Example() {
const columns: DataTableColumn<Invoice>[] = [
{ id: "id", header: "Invoice" },
{ id: "customer", header: "Customer" },
{ id: "due", header: "Due" },
{ id: "amount", header: "Amount", numeric: true, cell: ({ row }) => formatCurrency(row.amount, "USD", "en-US", 2) },
];
return (
<DataTable caption="Recent invoices" data={invoices} columns={columns} hidePagination />
);
}Animated sort
Click a column header: rows slide to their new place (transform only, spring.smooth) instead of swapping. It is on by default (animateRows) and instant with reduced motion. For any other list, AnimatedList and AnimatedListItem do the same on insert, remove and reorder.
import { useState } from "react";
import { DataTable } from "@/components/sheenui/data-table/data-table";
import { type DataTableColumn } from "@/components/sheenui/data-table/types";
import { AnimatedList, AnimatedListItem } from "@/components/sheenui/motion/reorder";
// Package build (after the first npm release, or a packed tarball): import { AnimatedList, AnimatedListItem, DataTable, type DataTableColumn } from "@sheenui/theme";
type Invoice = { id: string; customer: string; amount: number };
const invoices: Invoice[] = [
{ id: "INV-1001", customer: "Acme Corp", amount: 1280 },
{ id: "INV-1002", customer: "Globex", amount: 640 },
{ id: "INV-1003", customer: "Initech", amount: 2210 },
];
const columns: DataTableColumn<Invoice>[] = [
{ id: "id", header: "Invoice" },
{ id: "customer", header: "Customer" },
{ id: "amount", header: "Amount", numeric: true },
];
export function Example() {
const [names, setNames] = useState(invoices.map((invoice) => invoice.customer));
return (
<>
<DataTable caption="Invoices" data={invoices} columns={columns} animateRows hidePagination />
<button type="button" onClick={() => setNames((list) => [...list].reverse())}>
Reverse
</button>
<AnimatedList>
{names.map((name) => (
<AnimatedListItem key={name}>{name}</AnimatedListItem>
))}
</AnimatedList>
</>
);
}Loading and error states
While the first request runs the table shows skeleton rows with a sweep of light and a progress bar under the header. When it fails, an inline alert with a Retry button replaces the body (rows that were already on screen stay under a veil, with the alert below them).
import { DataTable } from "@/components/sheenui/data-table/data-table";
import { type DataTableColumn } from "@/components/sheenui/data-table/types";
// Package build (after the first npm release, or a packed tarball): import { DataTable, type DataTableColumn } from "@sheenui/theme";
type Invoice = { id: string; customer: string; due: string };
const columns: DataTableColumn<Invoice>[] = [
{ id: "id", header: "Invoice" },
{ id: "customer", header: "Customer" },
{ id: "due", header: "Due" },
];
export function Example() {
return (
<div className="flex flex-col gap-6">
<DataTable caption="Loading invoices" data={[]} columns={columns} loading hidePagination enableSearch={false} />
<DataTable
caption="Invoices that failed to load"
data={[]}
columns={columns}
error="The billing service timed out. Check your connection and try again."
onRetry={() => undefined}
hidePagination
enableSearch={false}
/>
</div>
);
}Ten thousand rows
With maxHeight set, a page of 50 rows or more renders only the rows in view plus a few more (virtualize defaults to auto; pass virtualize to force it). Scroll to the end: the count below stays small, yet the scrollbar spans all 10,000. Rows outside the window are not in the DOM, so Tab skips them: set virtualize={false} for a table people tab through row by row.
import { useEffect, useState } from "react";
import { formatCurrency } from "@/components/sheenui/data-table/cells";
import { DataTable } from "@/components/sheenui/data-table/data-table";
import { type DataTableColumn } from "@/components/sheenui/data-table/types";
// Package build (after the first npm release, or a packed tarball): import { DataTable, formatCurrency, type DataTableColumn } from "@sheenui/theme";
type Order = { id: string; customer: string; status: string; total: number };
const statuses = ["Paid", "Pending", "Shipped", "Refunded"];
const orders: Order[] = Array.from({ length: 10_000 }, (_, i) => ({
id: `ORD-${String(i + 1).padStart(5, "0")}`,
customer: `Customer ${String(((i * 37) % 900) + 100)}`,
status: statuses[i % statuses.length] ?? "Paid",
total: 20 + ((i * 7919) % 48000) / 100,
}));
const columns: DataTableColumn<Order>[] = [
{ id: "id", header: "Order", minWidth: 120 },
{ id: "customer", header: "Customer", minWidth: 150 },
{ id: "status", header: "Status", minWidth: 110 },
{
id: "total",
header: "Total",
numeric: true,
minWidth: 110,
cell: ({ row }) => formatCurrency(row.total, "USD", "en-US", 2),
},
];
export function Example() {
const [wrapper, setWrapper] = useState<HTMLDivElement | null>(null);
const [inDom, setInDom] = useState<number | null>(null);
useEffect(() => {
if (!wrapper) return;
const count = () => setInDom(wrapper.querySelectorAll("tbody tr[data-row-id]").length);
count();
const observer = new MutationObserver(count);
observer.observe(wrapper, { childList: true, subtree: true });
return () => observer.disconnect();
}, [wrapper]);
return (
<div ref={setWrapper} className="flex w-full flex-col gap-3">
<p className="text-sm text-sheen-fg-muted">Rows in the DOM: {inDom} of 10,000</p>
<DataTable
caption="Orders"
data={orders}
columns={columns}
maxHeight="22rem"
virtualize
hidePagination
defaultPageSize={10_000}
/>
</div>
);
}Pagination on its own
A nav landmark with aria-current on the current page. The number of slots stays the same as you page, so buttons never jump under the pointer; on phones it collapses to “Page x of y”.
import { useState } from "react";
import { Pagination } from "@/components/sheenui/pagination/pagination";
// Package build (after the first npm release, or a packed tarball): import { Pagination } from "@sheenui/theme";
export function Example() {
const [page, setPage] = useState(6);
return (
<>
<Pagination page={page} pageCount={24} onPageChange={setPage} aria-label="Search results pages" />
<Pagination page={page} pageCount={24} onPageChange={setPage} size="sm" showFirstLast={false} siblingCount={2} />
<Pagination defaultPage={2} pageCount={5} getPageHref={(p) => `?page=${p}`} />
</>
);
}Keyboard
Accessibility
- Semantic table: a caption, column headers with scope, aria-sort on the primary sorted column. Secondary sorts are read out on their header buttons.
- Sortable headers are buttons; Shift + Enter (or Shift-click) adds a column to the sort. A plain click on a column of a multi-sort makes it the only sort. Escape clears the search box.
- Checkboxes are named after their row (“Select row Ravi Kumar”); Shift-click selects a range.
- One polite live region announces result counts, sorting, page and page-size changes, and selection.
- Search ignores case and accents (“cafe” finds “Café”) and only looks at visible columns, so every match is marked.
- Focus never drops to the page: clearing the search, removing a filter chip, clearing the selection or deleting rows moves it to the next sensible control. Focused cells are kept clear of the sticky header, the pinned columns and the selection bar.
- The scroll area is focusable (and a named region) when it overflows, so it can be scrolled with arrow keys. Focus outlines are solid; touch targets are 44px; forced-colors mode is supported.
DataTable props
DataTableLabels keys and English defaults (60)
Column options
Pagination props
The pager under the table is the Pagination component. Its props (page, onPageChange, pageCount, siblingCount and the rest) are listed on its page.
Cell helpers
CurrencyCell props
Highlight props
ProgressCell props
RelativeDateCell props
StatusCell props
UserCell props
All exports on this page
CurrencyCell— A money amount, right-aligned digits (tabular figures) formatted with Intl for the locale.DataTable— A full data table: global search with highlighted matches, multi-column sorting, faceted filters, row selection with bulk actions.Highlight— Highlight as a component: wraps every match of query in a <mark>, ignoring case and accents (the same matching as the table search).ProgressCell— A small progress bar with the percentage beside it, for usage or completion columns.RelativeDateCell— A date as relative text ("3 days ago", "in 2 hours") inside a <time>.StatusCell— A status as a dotted Badge.UserCell— A table cell for a person: avatar, name and an optional email.defaultDataTableLabels— Default English strings of DataTableLabels; spread it and override single keys to reword.foldText— Text as the search compares it: lower case, accents removed, ß → ss, … so "cafe" finds "Café".formatCurrency— value as money in currency (default "USD") for locale (default: the browser's), with maximumFractionDigits decimals (default 0).formatRelativeDate— "3 days ago", "in 2 hours".highlightText— Wrap every match of query in a <mark>.
When to use the data table
- Use DataTable as a React table with filters and pagination for an admin list of users or orders where people need search with highlighted matches, multi-column sorting and a faceted Status filter with counts. If you are looking for a shadcn data table alternative, this one comes with sorting, paging, selection and a caption in a single component.
- Use enableSelection with bulkActions for a list where people pick rows across several pages and then export, archive or delete them from the floating selection bar.
- Use manual with rowCount and the controlled sorting, pagination and filter props when the dataset lives on a server and only the current page is in memory.
- Skip it when you only need a few static rows or a key value layout. A plain table, DescriptionList or a stack of GlassCard items is lighter and easier to scan.
- Pair it with the Pagination component it already uses in its footer, Badge, Avatar and Progress through the StatusCell, UserCell and ProgressCell helpers, and Toast to confirm a bulk action or a finished CSV export.
SheenUI DataTable or the shadcn data table recipe?
The shadcn/ui data table is a recipe: you assemble columns, filters and pagination around TanStack Table yourself. SheenUI's DataTable is a finished component on TanStack Table v9: you pass data, columns and a caption and get search, faceted filters, multi-sort, pagination, row selection with bulk actions and a server mode through manual. Choose the recipe for full control of every cell; choose this one to skip the wiring.
Frequently asked questions
Related pages
Guides that cover it
67 components pages in all: browse them on All components.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .