Data grid
Table plus search, sorting, column visibility, paging and loading and empty states. This is what operational lists need.
Purpose
If the user ever has to find a row, you want DataGrid. It wraps
Table with everything an operational list needs — a search box,
sortable headers, a column-visibility menu, a pagination footer, and proper loading and empty
states — so a claims queue or member roster never gets rebuilt from primitives.
| Component | Use |
|---|---|
DataGrid | Operational lists: claims queues, member rosters, anything searched or paged. |
Table | Static, short lists: plan summaries, breakdowns inside a detail page. |
DescriptionList | One record's fields — a detail view is not a one-row table. |
Example
Columns are TanStack Table ColumnDefs (the type is re-exported from the subpath); cell
renderers compose freely with other components — badges, menus, avatars.
| CLM-48213 | Aisyah Rahman | Klinik Mediviron, KL Sentral | 85.00 | Approved |
| CLM-48214 | Lim Wei Jie | Poliklinik Bangsar | 120.00 | Pending |
| CLM-48215 | Priya Nair | Klinik Kita, Petaling Jaya | 45.00 | Approved |
| CLM-48216 | Tan Mei Ling | Klinik Idzham, Shah Alam | 310.00 | Denied |
| CLM-48217 | Ahmad Faiz | Gleneagles Medical Centre | 780.00 | Open |
10 rows
import { DataGrid, type ColumnDef } from "@healthmetrics/ui/data-grid";
import { Badge } from "@healthmetrics/ui/badge";
const columns: ColumnDef<Claim, unknown>[] = [
{ accessorKey: "id", header: "Claim", enableHiding: false },
{ accessorKey: "member", header: "Member" },
{
accessorKey: "amount",
header: "Amount (MYR)",
cell: ({ getValue }) => (
<span className="tabular-nums">{(getValue() as number).toFixed(2)}</span>
),
},
{
accessorKey: "status",
header: "Status",
cell: ({ getValue }) => <Badge variant="success">{getValue() as string}</Badge>,
},
];
<DataGrid columns={columns} data={claims} searchPlaceholder="Search claims…" pageSize={10} />;Per-column behaviour comes straight from the ColumnDef: enableHiding: false pins a column out
of the visibility menu (do this for identifiers), and enableSorting: false removes the sort
affordance from a header. hideToolbar drops the search box and column menu when the grid is
embedded somewhere those duplicate the page's own controls.
Everything is client-side and in-memory: the global filter, sorting and paging all operate on the
data you pass. There is no server-side pagination mode, no row selection, and no controlled
sort/filter state — if you need those, compose TanStack Table over the raw
Table parts instead.
States
loading swaps the body for five skeleton rows and the footer count for "Loading…" — the layout
holds its shape while data arrives.
Loading…
With no rows — an empty result or an over-eager search — a single centred cell shows emptyText.
Make it say what to do next, not just "No results."
| No claims match your filters. | ||||
0 rows
Structure
The tokens behind the grid — the table itself inherits everything from Table.
| Property | Value |
|---|---|
| Toolbar | search Input (max 320px, leading search glyph) + Columns menu |
| Container | 1px --border, --radius-xl, horizontal scroll |
| Header | SortableHead buttons, 44px rows, 12px uppercase |
| Loading | 5 Skeleton rows, one per visible column |
| Empty | single 112px centred cell, --muted-foreground |
| Footer | 12px row count + "Page X of Y", small outline previous/next buttons |
Best practices
Do
- Pin identifier columns with
enableHiding: false— a claims queue with the claim number hidden is unusable. - Render amounts with
tabular-numsin acell, right-aligned when compared. - Write specific
searchPlaceholderandemptyText— "Search claims…", "No claims match your filters.", not the defaults. - Keep row actions in a trailing
DropdownMenucell, not a strip of icon buttons.
Don't
- Reach for
DataGridon a short static list — that is Table, without the toolbar chrome. - Feed it one page of server data — filtering, sorting and paging are client-side and in-memory, so partial data silently searches and sorts only what it was given.
- Hide the toolbar on a list long enough to page — search is how users cope with volume.
- Truncate identifiers users copy (claim numbers) — wrap or widen instead.
Accessibility & keyboard
- Semantic
<table>markup throughout — real row and column navigation for screen readers. - Sortable headers are real
<button>s inside a<th>carryingaria-sort(ascending/descending/none), so sort state never relies on the arrow glyph alone. - The search input has
aria-label="Search table"; the pager buttons are labelled "Previous page" / "Next page" and disable at the bounds. - All glyphs (search, column, chevrons, sort arrows) are decorative and hidden from assistive tech — every control also has a text or ARIA name.
- The loading state is visual only — skeleton rows make no announcement. If load times are long, announce progress at page level.
- Keyboard: Tab reaches search → Columns menu → each sortable header → the pager;
Enter/Space toggles sort, opens the menu and activates paging. The column menu is a
DropdownMenu— arrow keys move between checkboxes, Escape closes.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
columnsrequired | ColumnDef<TData, unknown>[] | — | — |
datarequired | TData[] | — | — |
loading | boolean | undefined | — | Render skeleton rows instead of data (Figma "Loading" state). |
emptyText | string | undefined | "No results." | Message for the empty state. |
searchPlaceholder | string | undefined | "Search…" | Placeholder for the global search box. |
hideToolbar | boolean | undefined | — | Hide the toolbar (search + column visibility). |
pageSize | number | undefined | 10 | Rows per page. |
className | string | undefined | — | — |