Data display
DataGrid
Free25.2 KB gzippedAn interactive data table (WAI-ARIA APG "Data Grid"): sortable columns (with Shift for multi-column sorts), search filtering, single or multiple row selection, pagination, and a full keyboard model. Works with client-side data, or server-side data with manual.
Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Tab, Arrow keys, Home and 11 more · Full report
More in Pro
DataGrid is free. DataGridPro, in the paid Pro add-on, takes every prop on this page and adds column tools, filters, grouping, editing, and copy and paste. CSV and Excel export, also in Pro, downloads exactly what the grid shows.Import
import { DataGrid } from "@vjdesigns/vjdesigns-ui";
Importing only DataGrid adds about 25.2 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.
Examples
Basic
The grid is one tab stop: arrow keys move between cells, Enter on a header sorts (Shift+Enter adds a second sort), and screen readers hear sort changes. rowHeader makes that column name its rows.
import { DataGrid } from "@vjdesigns/vjdesigns-ui";
const roster = [
{ id: 1, name: "Jordan Reyes", position: "Guard", ppg: 18.4, apg: 7.1 },
{ id: 2, name: "Avery Chen", position: "Forward", ppg: 15.2, apg: 2.4 },
{ id: 3, name: "Sam Okafor", position: "Center", ppg: 12.9, apg: 1.8 },
{ id: 4, name: "Riley Park", position: "Guard", ppg: 11.6, apg: 5.3 },
{ id: 5, name: "Morgan Diaz", position: "Forward", ppg: 9.8, apg: 2.9 },
{ id: 6, name: "Casey Lin", position: "Guard", ppg: 8.7, apg: 4.4 },
{ id: 7, name: "Taylor Brooks", position: "Center", ppg: 7.5, apg: 1.1 },
];
const rosterColumns = [
{ key: "name", header: "Player", sortable: true, rowHeader: true },
{ key: "position", header: "Position", sortable: true },
{ key: "ppg", header: "Points", sortable: true, numeric: true },
{ key: "apg", header: "Assists", sortable: true, numeric: true },
];
export function Basic() {
return <DataGrid aria-label="Roster" rows={roster} columns={rosterColumns} getRowId={(p) => p.id} />;
}
Search and selection
filter searches the rows, and the result count is announced. selectionMode="multiple" adds checkboxes: Space selects a row, Shift+Space a range, Ctrl/⌘+A every row. pageSize adds pagination.
import { useState } from "react";
import {
DataGrid,
Field,
SearchInput,
Stack,
type DataGridRowId,
} from "@vjdesigns/vjdesigns-ui";
const roster = [
{ id: 1, name: "Jordan Reyes", position: "Guard", ppg: 18.4, apg: 7.1 },
{ id: 2, name: "Avery Chen", position: "Forward", ppg: 15.2, apg: 2.4 },
{ id: 3, name: "Sam Okafor", position: "Center", ppg: 12.9, apg: 1.8 },
{ id: 4, name: "Riley Park", position: "Guard", ppg: 11.6, apg: 5.3 },
{ id: 5, name: "Morgan Diaz", position: "Forward", ppg: 9.8, apg: 2.9 },
{ id: 6, name: "Casey Lin", position: "Guard", ppg: 8.7, apg: 4.4 },
{ id: 7, name: "Taylor Brooks", position: "Center", ppg: 7.5, apg: 1.1 },
];
const rosterColumns = [
{ key: "name", header: "Player", sortable: true, rowHeader: true },
{ key: "position", header: "Position", sortable: true },
{ key: "ppg", header: "Points", sortable: true, numeric: true },
{ key: "apg", header: "Assists", sortable: true, numeric: true },
];
export function SearchAndSelection() {
const [query, setQuery] = useState("");
const [selected, setSelected] = useState<DataGridRowId[]>([]);
return (
<Stack gap={4} style={{ width: "100%" }}>
<Field label="Search players">
<SearchInput value={query} onValueChange={setQuery} />
</Field>
<DataGrid
aria-label="Roster"
rows={roster}
columns={rosterColumns}
getRowId={(p) => p.id}
filter={query}
selectionMode="multiple"
selected={selected}
onSelectedChange={setSelected}
pageSize={5}
/>
</Stack>
);
}
Row details
renderRowDetail adds a full-width row under a row (master-detail), or nothing when it returns null. Controls in it are outside the arrow-key grid: Tab from the row moves into them. Grids with detail rows don't virtualize, so pair them with pageSize.
import { DataGrid, Text } from "@vjdesigns/vjdesigns-ui";
const roster = [
{ id: 1, name: "Jordan Reyes", position: "Guard", ppg: 18.4, apg: 7.1 },
{ id: 2, name: "Avery Chen", position: "Forward", ppg: 15.2, apg: 2.4 },
{ id: 3, name: "Sam Okafor", position: "Center", ppg: 12.9, apg: 1.8 },
{ id: 4, name: "Riley Park", position: "Guard", ppg: 11.6, apg: 5.3 },
{ id: 5, name: "Morgan Diaz", position: "Forward", ppg: 9.8, apg: 2.9 },
{ id: 6, name: "Casey Lin", position: "Guard", ppg: 8.7, apg: 4.4 },
{ id: 7, name: "Taylor Brooks", position: "Center", ppg: 7.5, apg: 1.1 },
];
const rosterColumns = [
{ key: "name", header: "Player", sortable: true, rowHeader: true },
{ key: "position", header: "Position", sortable: true },
{ key: "ppg", header: "Points", sortable: true, numeric: true },
{ key: "apg", header: "Assists", sortable: true, numeric: true },
];
const injuries: Record<number, string> = {
2: "Ankle sprain. Day to day, expected back for Friday's game.",
5: "Concussion protocol. Cleared for non-contact practice.",
};
export function RowDetails() {
return (
<DataGrid
aria-label="Roster with injury notes"
rows={roster}
columns={rosterColumns}
getRowId={(p) => p.id}
pageSize={5}
renderRowDetail={(p) => (injuries[p.id] ? <Text size="sm">{injuries[p.id]}</Text> : null)}
/>
);
}
Large data
100,000 rows. Above 100 rows the grid renders only the rows in view (virtualize="auto"), so scrolling, sorting, searching and selecting stay instant. Screen readers still hear the full count and each row's position. Search ignores accents: "zoe" finds "Zoë". Ctrl+End jumps to the last row.
import { useState } from "react";
import { DataGrid, Field, SearchInput, Stack } from "@vjdesigns/vjdesigns-ui";
const firstNames = ["Jordan", "Avery", "Sam", "Riley", "Casey", "Drew", "Jamie", "Quinn", "José", "Zoë"];
const lastNames = ["Reyes", "Chen", "Okafor", "Novak", "Patel", "Larsen", "Alvarez", "Silva", "Ibáñez", "Nakamura"];
const positions = ["Guard", "Forward", "Center"];
const lastNames = ["Reyes", "Chen", "Okafor", "Novak", "Patel", "Larsen", "Alvarez", "Silva", "Ibáñez", "Nakamura"];
const positions = ["Guard", "Forward", "Center"];
const positions = ["Guard", "Forward", "Center"];
const manyPlayers = Array.from({ length: 100_000 }, (_, i) => ({
id: i + 1,
name: `${firstNames[(i * 7) % firstNames.length]} ${lastNames[(i * 13) % lastNames.length]} ${i + 1}`,
position: positions[i % positions.length],
ppg: ((i * 37) % 300) / 10,
apg: ((i * 11) % 100) / 10,
}));
const sizedColumns = [
{ key: "name", header: "Player", sortable: true, rowHeader: true, width: "40%" },
{ key: "position", header: "Position", sortable: true },
{ key: "ppg", header: "Points", sortable: true, numeric: true },
{ key: "apg", header: "Assists", sortable: true, numeric: true },
];
export function LargeData() {
const [query, setQuery] = useState("");
return (
<Stack gap={4} style={{ width: "100%" }}>
<Field label="Search 100,000 players">
<SearchInput value={query} onValueChange={setQuery} />
</Field>
<DataGrid
aria-label="All players"
rows={manyPlayers}
columns={sizedColumns}
getRowId={(p) => p.id}
filter={query}
selectionMode="multiple"
maxHeight={400}
/>
</Stack>
);
}
Right to left
The first example again, inside a right-to-left LocaleProvider (Arabic). Layout, spacing and arrow icons mirror, and the components' built-in text is translated. The example's own text stays in English.
Basic
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";
// Basic is the "Basic" example above.
<LocaleProvider locale="ar" messages={ar}>
<Basic />
</LocaleProvider>
Usage notes
Keyboard: the grid is one Tab stop. Arrow keys move between cells (mirrored in RTL), Home / End go to the row's first or last cell, Ctrl+Home / Ctrl+End to the first or last cell of the grid, Page Up / Page Down move ten rows. On a header, Enter sorts (Shift+Enter adds a secondary sort). Space selects the row, Shift+click or Shift+Space selects a range, and Ctrl/⌘+A selects every row. A cell with a single button, link, or checkbox focuses it directly; for cells with several controls or a text field, Enter or F2 moves into the cell, Tab cycles inside it, and Escape returns to the grid.
Screen readers hear sort changes and filter result counts; the grid is a real <table role="grid"> with aria-sort, aria-selected, aria-rowcount, and aria-rowindex.
<DataGrid
aria-label="Roster"
rows={players}
columns={[
{ key: "name", header: "Player", sortable: true, rowHeader: true },
{ key: "ppg", header: "PPG", sortable: true, numeric: true },
]}
selectionMode="multiple"
pageSize={10}
/>
API reference
DataGrid
New in 1.5.0| Prop | Type | Default |
|---|---|---|
rowsRequiredThe data. Sorting, filtering, and paging work on a copy; this array is never mutated. | readonly T[] | — |
columnsRequiredThe columns, in display order. | readonly DataGridColumn<T>[] | — |
getRowIdA stable id for each row. | (row: T) => DataGridRowId | (row) => row.id |
getRowLabelReadable name of a row, for its checkbox ("Select Jordan Reyes"). Defaults to the | (row: T) => string | — |
aria-labelAccessible name of the grid. Required unless | string | — |
aria-labelledbyId of a visible heading that names the grid. | string | — |
aria-describedbyId of text that describes the grid. | string | — |
sortActive sort, primary first (controlled). | DataGridSortItem[] | — |
defaultSortInitial sort when uncontrolled. | DataGridSortItem[] | [] |
onSortChangeCalled with the next sort. | (sort: DataGridSortItem[]) => void | — |
multiSortShift+click (or Shift+Enter) on a header adds it as a secondary sort. | boolean | true |
filterSearch text: rows are kept when their filterable columns contain every word (case- and diacritic-insensitive). Render your own search field (e.g. | string | — |
selectionModeHow rows are selected. | "none""single""multiple" | "none" |
selectedSelected row ids (controlled). | DataGridRowId[] | — |
defaultSelectedInitially selected row ids when uncontrolled. | DataGridRowId[] | [] |
onSelectedChangeCalled with the next selected ids. | (selected: DataGridRowId[]) => void | — |
isRowSelectableRows that can't be selected (their checkbox is disabled). | (row: T) => boolean | — |
pageSizeRows per page. Shows a footer with the range and | number | — |
virtualizeRender only the rows in view (plus a few above and below), so grids of 100,000+ rows scroll, sort, filter, and select without delay. | falsetrue"auto" | "auto" |
pageCurrent page, starting at 1 (controlled). | number | — |
defaultPageInitial page when uncontrolled. | number | 1 |
onPageChangeCalled with the next page. | (page: number) => void | — |
manualServer-side data: the grid doesn't sort, filter, or page | boolean | false |
rowCountTotal rows on the server, with | number | rows.length |
onRowActivateCalled when a row is activated: Enter on one of its cells, or a click on a non-interactive part of it. | (row: T) => void | — |
loadingShows a loading state and marks the grid | boolean | false |
emptyStateShown when there are no rows. Defaults to "No rows" (or "No matching rows" while filtering). | ReactNode | — |
densityRow height and padding. | "compact""comfortable""spacious" | "comfortable" |
variantVisual style. | "plain""striped""outline" | "outline" |
hoverableHighlight rows under the pointer. | boolean | true |
stickyHeaderKeep the header row visible while scrolling. | boolean | true |
maxHeightMaximum height of the scrolling body (CSS length, or px as a number). | CSSProperties["maxHeight"] | — |
layoutTable layout. | "auto""fixed" | "auto" ("fixed" while virtualized) |
tableStyleStyle for the | CSSProperties | — |
classNameClass name for the outer frame. | string | — |
styleStyle for the outer frame. | CSSProperties | — |
refRef to the | Ref<HTMLTableElement> | — |
treegridRows form a hierarchy (groups, a tree): the table becomes a | boolean | false |
getRowPropsPer-row level, expanded state, and class name. | (row: T) => DataGridRowProps | — |
renderRowDetailContent for a full-width row under a row (master-detail), or null for none. Its controls are outside the grid's arrow-key navigation: Tab from the row moves into them. A grid with detail rows doesn't virtualize, so pair it with | (row: T) => ReactNode | — |
onRowsShownCalled with the rows the grid shows, sorted, filtered, and paged, in display order, whenever they change (to copy a cell range, or export exactly what's on screen). | (rows: readonly T[]) => void | — |
onVisibleRangeChangeCalled with the range of shown rows (indexes into them, inclusive) that are rendered in view. With virtualization this follows scrolling, which is what "load more while scrolling" needs. | (range: { start: number; end: number; }) => void | — |
See what changed in each version in the Changelog.
Accessibility report
DataGrid targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.
axe-core audit (live)
Checking the examples above…
Lighthouse audit
Light mode
Score 10037 passed · 0 failed · 28 not applicable · 10 to check by hand
Dark mode
Score 10037 passed · 0 failed · 28 not applicable · 10 to check by hand
Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.
Built-in behavior
Keyboard
| Key | Action |
|---|---|
| Tab | The grid is one tab stop; Tab moves in and out of it. |
| Arrow keys | Move between cells (mirrored right to left). |
| HomeEnd | First or last cell in the row. |
| Ctrl+HomeCtrl+End | First or last cell in the grid. |
| Page UpPage Down | Move ten rows. |
| Enter | On a header: sorts by it (Shift+Enter adds a second sort). On a row: onRowActivate. In a cell with controls: moves into the cell. |
| F2 | Moves into a cell with several controls or a text field; Tab then cycles inside it. |
| Escape | Returns from inside a cell to the grid. |
| Space | Selects the row (Shift+Space: a range). |
| Ctrl+A⌘+A | Multiple selection: selects every row. |
A cell with a single button, link or checkbox focuses that control directly. Above 100 rows only the rows in view are rendered; the focused row stays rendered while you scroll away, so focus is never lost, and Ctrl+End scrolls to the last row and focuses it.
Roles and states
| Element | Role | States and properties |
|---|---|---|
<table> | grid (treegrid with treegrid) | aria-label, aria-rowcount (the full count, also while virtualized) |
| Header cell | columnheader | aria-sort on the sorted column |
| Row | row | aria-rowindex (its position in the full list), aria-selected when rows are selectable, aria-level and aria-expanded from getRowProps in a treegrid |
| Detail row | row | A full-width cell under its row (renderRowDetail); Tab from the row moves into its controls |
| Cell | gridcell / rowheader | The rowHeader column names each row |
| Live region | status | Announces sort changes and filter result counts |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck. | 2.1.1 (A), 2.1.2 (A) |
| Focus | Focus moves in a logical order, is always visible, and isn't hidden behind sticky headers. | 2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA) |
| Screen readers | Names, roles and states are announced correctly, and status changes are announced without moving focus. | 1.3.1 (A), 4.1.2 (A), 4.1.3 (AA) |
| Color | Meaning never depends on color alone; your own colors meet contrast in both modes. | 1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA) |
| Zoom and reflow | At 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed. | 1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA) |
| Pointer targets | Click and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap. | 2.5.8 (AA), 2.5.5 (AAA) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |