A React data table needs a few rules before any library: real <table> markup with a caption, numbers right-aligned in tabular figures, a sticky header, sortable headers built as buttons with aria-sort, and clear empty and loading states. For the code, pick by need: write it yourself for simple lists, TanStack Table for headless control, AG Grid or MUI X for spreadsheet-like grids.
This guide gives you the design rules, a library-free sortable DataTable component you can paste into a React project, and a decision table that compares the main React table libraries by license and features, using each project's own documentation. HorizonX does not sell a data table kit, so the code here is the deliverable. For the dashboards these tables usually live in, see the HorizonX dashboard templates collection.
Table or grid: decide first
The WAI-ARIA Authoring Practices separate two things that look identical. A table "is a static tabular structure ... it is not an interactive widget", so its cells are not focusable, and a sort button inside a header is just another stop in the tab order. A grid is "an interactive widget that has a tabular structure", where arrow keys move between cells (APG table pattern, APG grid pattern).
Most dashboard tables (invoices, orders, users, logs) are tables: people read rows, sort a column, maybe click a link. Spreadsheet behaviour such as editing cells in place, selecting ranges or moving with arrow keys makes it a grid, and that is where a grid library earns its weight. Building an accessible grid by hand is a large project; building an accessible table is an afternoon.
Data table design rules
- Give it a caption.
<caption>gives the table its accessible name and tells sighted readers what they are looking at before they scan the cells (MDN caption). - Right-align numbers and use tabular figures.
font-variant-numeric: tabular-numsgives every digit the same width, so amounts line up by place value and are easy to compare down a column (MDN font-variant-numeric). Text stays left-aligned. - Keep the header visible. A sticky
<thead>inside a scrolling container keeps column names on screen. The example below usesborder-collapse: separateand draws the header line on the header cells themselves, so the line moves with the sticky row. - Make sortable headers buttons. The APG sortable table example sets
aria-sort"on the currently sorted column", wraps the header text in a<button>, and hides the arrow characters witharia-hidden="true"so they do not become part of the button name (APG sortable table, MDN aria-sort). - Mark the row header. The first cell of each row (invoice number, name) is a
<th scope="row">, so a screen reader announces it as you move across the row. - Let wide tables scroll, and make that reachable. A scroll container with
tabindex="0",role="region"and a label can be scrolled with the keyboard. - Design the empty, loading and error states. "No invoices yet" in the table body beats a blank box. Keep the header visible during loading so the layout does not jump.
- Do not hide data behind hover. Row actions that appear only on hover are invisible on touch screens and hard to reach with a keyboard.
- Paginate or virtualize long lists. Up to a few hundred rows, render them. Beyond that, paginate when people look for specific records (our pagination component guide covers the patterns), or virtualize when they scroll through a stream, for example with TanStack Virtual.

A sortable DataTable in React, no library
Sorting lives in a plain function so you can test it without React. It copies the array, compares text with Intl.Collator so "INV-2" comes before "INV-10", and keeps empty cells at the bottom in both directions (MDN Intl.Collator). Array.prototype.sort has been stable since ES2019, so rows with equal values keep their previous order (MDN Array.sort).
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' });
export function sortRows(rows, column, direction) {
if (!column) return rows;
const sign = direction === 'ascending' ? 1 : -1;
return [...rows].sort((a, b) => {
const x = a[column.key];
const y = b[column.key];
if (x == null || y == null) return x == null ? (y == null ? 0 : 1) : -1; // empty cells always last
const result = column.type === 'number' ? x - y : collator.compare(String(x), String(y));
return result * sign;
});
}
The component follows the design rules above: caption, scroll region, header buttons with aria-sort, row headers and an empty state. Pass sortable: false for columns that should not sort, and type: 'number' for right-aligned numeric columns.
import { useId, useMemo, useState } from 'react';
import { sortRows } from './sort-rows.js';
export function DataTable({ caption, columns, rows, emptyMessage = 'No rows to show.' }) {
const [sort, setSort] = useState({ key: null, direction: 'ascending' });
const captionId = useId();
const column = columns.find((col) => col.key === sort.key);
const sorted = useMemo(() => sortRows(rows, column, sort.direction), [rows, column, sort.direction]);
function toggle(key) {
setSort((prev) => ({
key,
direction: prev.key === key && prev.direction === 'ascending' ? 'descending' : 'ascending',
}));
}
return (
<div className="table-scroll" role="region" aria-labelledby={captionId} tabIndex={0}>
<table>
<caption id={captionId}>{caption}</caption>
<thead>
<tr>
{columns.map((col) => {
const active = sort.key === col.key;
return (
<th
key={col.key}
scope="col"
className={col.type === 'number' ? 'num' : undefined}
aria-sort={active ? sort.direction : undefined}
>
{col.sortable === false ? col.label : (
<button type="button" onClick={() => toggle(col.key)}>
{col.label}
<span aria-hidden="true">{active ? (sort.direction === 'ascending' ? '▲' : '▼') : '↕'}</span>
</button>
)}
</th>
);
})}
</tr>
</thead>
<tbody>
{sorted.length === 0 ? (
<tr>
<td colSpan={columns.length}>{emptyMessage}</td>
</tr>
) : (
sorted.map((row) => (
<tr key={row.id}>
{columns.map((col, index) => {
const Cell = index === 0 ? 'th' : 'td';
const value = row[col.key];
return (
<Cell
key={col.key}
scope={index === 0 ? 'row' : undefined}
className={col.type === 'number' ? 'num' : undefined}
>
{value == null ? '' : col.format ? col.format(value) : value}
</Cell>
);
})}
</tr>
))
)}
</tbody>
</table>
</div>
);
}
Using it, with example data (not real customers):
import { DataTable } from './DataTable.jsx';
const usd = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' });
const columns = [
{ key: 'id', label: 'Invoice' },
{ key: 'client', label: 'Client' },
{ key: 'due', label: 'Due date' },
{ key: 'amount', label: 'Amount', type: 'number', format: (v) => usd.format(v) },
{ key: 'status', label: 'Status', sortable: false },
];
// Example data, not real customers.
const rows = [
{ id: 'INV-1042', client: 'Northwind Studio', due: '2026-11-30', amount: 4200, status: 'Unpaid' },
{ id: 'INV-1039', client: 'Acme Labs', due: '2026-11-12', amount: 860.5, status: 'Paid' },
{ id: 'INV-1040', client: 'Blue Fern', due: null, amount: 12500, status: 'Draft' },
];
export function Invoices() {
return <DataTable caption="Invoices, November 2026" columns={columns} rows={rows} emptyMessage="No invoices yet." />;
}
The styles:
.table-scroll {
overflow: auto;
max-block-size: 70vh;
border: 1px solid #d5dbe3;
border-radius: 0.5rem;
}
.table-scroll:focus-visible {
outline: 2px solid #192c46;
outline-offset: 2px;
}
table {
inline-size: 100%;
border-collapse: separate; /* collapse breaks borders on sticky headers */
border-spacing: 0;
font-variant-numeric: tabular-nums;
}
caption {
padding: 0.75rem;
text-align: start;
font-weight: 600;
}
th,
td {
padding: 0.5rem 0.75rem;
border-block-end: 1px solid #e5e9ef;
text-align: start;
white-space: nowrap;
}
tbody th { font-weight: 500; }
thead th {
position: sticky;
inset-block-start: 0;
z-index: 1;
background: #f7f8fa;
border-block-end-color: #c3cad5;
}
.num { text-align: end; }
th button {
display: inline-flex;
align-items: center;
gap: 0.375rem;
padding: 0;
border: 0;
background: none;
color: inherit;
font: inherit;
font-weight: 600;
cursor: pointer;
}
th button:focus-visible {
outline: 2px solid #192c46;
outline-offset: 2px;
}
tbody tr:hover { background: #f5f7fa; }
How this was checked
On 2026-10-09 the sort function ran under Node 22 with assertions (numeric-aware text order, numbers, empty values last in both directions, input not mutated). The component rendered in Chromium with React 19: clicking and pressing Enter or Space on a header changed the order and moved aria-sort to that column, the empty state rendered across all columns, the scroll region took keyboard focus, and the header stayed fixed while the body scrolled. The CSS passed a syntax validator. Screen reader output was not tested.
Which React table library to use
Licenses and features below come from each project's own documentation and repository, checked on 2026-10-09. Check them again before you commit, because licensing terms change.
| Option | What it is | License | Good fit |
|---|---|---|---|
| Your own component (above) | Native table markup and a sort function | Yours | Read-only lists under a few hundred rows with sorting |
| TanStack Table | Headless logic: sorting, filtering, pagination, grouping state. "It is NOT a pre-built table component"; you render the markup | MIT (repository) | Custom designs that need filtering, pagination and column state |
| shadcn/ui data table | A guide, not a component: TanStack Table plus the shadcn Table, copied into your project | Your copy of the code | Projects already using shadcn/ui; it states "It doesn't make sense to combine all of these variations into a single component" |
| react-data-table-component | Pre-built table with sorting, pagination, row selection, inline editing, expandable rows and theming | Apache 2.0; React 18 or newer | A working table quickly, with its built-in look |
| AG Grid | Full data grid. Community includes sorting, filtering, pagination and editing | Community: MIT. Enterprise: commercial license (row grouping, aggregation, pivoting, server-side row model, exporting, among others) | Spreadsheet-like grids with large datasets |
| MUI X Data Grid | Full data grid in the Material UI ecosystem | Community: MIT. Pro (commercial) adds "multi-filtering, multi-sorting, column resizing, and column pinning"; Premium adds "row grouping and Excel exporting" | Apps already built on Material UI |
Two practical notes. First, headless (TanStack, shadcn) means you own the accessibility: the rules above still apply to the markup you write. Second, full grids bring their own keyboard model and styling system, so budget time for theming them to match your design.
Where these tables live: dashboard references
- Dashboard Components is a Figma set of KPI cards, a task list with tags and a calendar. It has no data table, which is a good reason to pair it with the component above.
- Invoicing Center Dashboard is a Figma dashboard built around an unpaid invoices list with statuses, close to the example data in this article.
- Financial Dashboard is a Figma dashboard with a recent activity list next to its charts.
For a comparison of complete dashboard kits, see the dashboard UI kit teardown.

FAQ
What React library do people use for data tables?
It comes up often on developer forums, and there is no single answer because the question hides two different needs. If you need a table (read, sort, paginate), plain markup or a headless library such as TanStack Table keeps your design intact. If you need a grid (edit cells, group rows, export, very large datasets), a full grid such as AG Grid or MUI X saves months of work; check which of those features sit in the free tier before you pick one.
Is a shadcn table the same as a shadcn data table?
No. The shadcn Table is styled table markup. The shadcn data table is a documented recipe that adds TanStack Table on top for sorting, filtering, pagination and row selection.
Should I use a table or a list of cards on mobile?
Keep the table when people compare values across rows, and let it scroll horizontally inside its region with the row header first. Switch to cards when each row is read on its own, such as a contact list.
Next step
Paste the DataTable component into your project, swap in your columns, and check it against the nine rules. For dashboard layouts to put it in, browse the HorizonX dashboard templates collection.