DataTable

A feature-rich table powered by TanStack Table.

Import

import { DataTable } from '@matix/components/data-table';

Usage

DataTable renders a styled table from a TanStack Table instance. Install @tanstack/react-table v9 as a peer dependency: bun add @tanstack/react-table.

v9 makes features opt-in. Build a feature set with tableFeatures() and pass it to useTable(). DataTable reads sorting, column visibility and row selection when the set includes them, and falls back to the core row API when it does not.

Alice Chenalice@example.comAdminActive
Bob Martinezbob@example.comEditorActive
Carol Singhcarol@example.comViewerInvited
Dan Parkdan@example.comEditorSuspended
Eva Nguyeneva@example.comViewerActive

Multi-Select

Pass the result of useRowSelection as selection. DataTable only reads it, so a table without selection carries none of the interaction code.

Keep rowSelectionFeature in the feature set and run the hook controlled against it. TanStack then stays the single source of truth, which matters once the table sorts: the ids stay attached to rows rather than to positions.

Add a leading display column for the checkboxes. Build the columns once and let the cells read the selection through a ref — a cell that closed over selection would go stale, and putting it in the useMemo deps would rebuild the table on every render. Cells re-render whenever the selection changes, so the ref is always fresh when read.

Actions
webproductionReady
webstagingReady
apiproductionBuilding
apipreviewFailed
workerproductionReady
workerstagingReady
docspreviewReady

The gesture table, the checkbox column, the rules for clickable cell content and the full option reference live on the Table page. Selection also works with the hook's own uncontrolled state — drop value and onValueChange — but then sorting the table will not carry the selection with it, so prefer the controlled form here.

With Sorting

Add rowSortingFeature and a sortedRowModel to the feature set. Column headers become interactive automatically.

import {
  createColumnHelper,
  createSortedRowModel,
  rowSortingFeature,
  sortFns,
  tableFeatures,
  useTable,
} from '@tanstack/react-table';

const features = tableFeatures({
  rowSortingFeature,
  sortedRowModel: createSortedRowModel(),
  sortFns,
});
const columnHelper = createColumnHelper();

const columns = [
  columnHelper.accessor('name', { header: 'Name' }),
  columnHelper.accessor('created', { header: 'Created' }),
  columnHelper.accessor('size', { header: 'Size (KB)' }),
];

const data = [
  { name: 'readme.md', created: '2026-01-10', size: 4 },
  { name: 'index.ts', created: '2026-02-15', size: 12 },
  { name: 'styles.css', created: '2026-03-01', size: 8 },
];

function Demo() {
  const [sorting, setSorting] = React.useState([]);

  const table = useTable({
    features,
    data,
    columns,
    state: { sorting },
    onSortingChange: setSorting,
  });

  return <DataTable table={table} />;
}

<Demo />;

With Toolbar

Pass a toolbar slot to render content above the table (filters, search, actions).

Alice Chenalice@example.comAdmin
Bob Martinezbob@example.comEditor
Carol Singhcarol@example.comViewer
Dan Parkdan@example.comEditor
Eva Nguyeneva@example.comViewer
5 of 5

With Pagination

Pass a pagination slot for a pagination control below the table.

#NameOwner
1Item 1Alice
2Item 2Bob
3Item 3Carol
4Item 4Dan
5Item 5Alice
Page 1 of 5

The first click on a column sorts in the order that TanStack picks. For number columns, this order is descending. Set sortDescFirst: false on the column to sort ascending first. Set it on the table to change every column.

import {
  createColumnHelper,
  createSortedRowModel,
  rowSortingFeature,
  sortFns,
  tableFeatures,
  useTable,
} from '@tanstack/react-table';

const features = tableFeatures({
  rowSortingFeature,
  sortedRowModel: createSortedRowModel(),
  sortFns,
});
const columnHelper = createColumnHelper();

const columns = [
  columnHelper.accessor('name', { header: 'Name' }),
  columnHelper.accessor('size', {
    header: 'Size (KB)',
    sortDescFirst: false,
    meta: { align: 'end' },
  }),
];

const data = [
  { name: 'readme.md', size: 4 },
  { name: 'index.ts', size: 12 },
  { name: 'styles.css', size: 8 },
];

function Demo() {
  const table = useTable({ features, data, columns });

  return <DataTable table={table} />;
}

<Demo />;

Each sort button has an aria-label such as Sort by Name, ascending. It names the column and the direction that the next click applies. Pass sortLabel to change the text, for example to translate it. A column meta.label sets the column name when the header is not a string.

Column Alignment

Set meta.align on a column to align the header and the body cells: 'start' (default), 'center', or 'end'. Use 'end' for numbers. Set meta.headerSx or meta.cellSx to add StyleX styles to the <th> or the <td> of that column.

#1042Alice Chen$129.50
#1043Bob Martinez$18.00
#1044Carol Singh$74.25

Empty State

Pass emptyState to show one full-width row when the table has no rows.

NameOwner
No items match “zzz”.

Table Props

Pass tableProps to forward props to the inner Table. For example, tableProps={{ contained: false }} removes the bordered wrapper.

Custom Styles

import * as stylex from '@stylexjs/stylex';
import { createColumnHelper, tableFeatures, useTable } from '@tanstack/react-table';

const custom = stylex.create({
  striped: { fontSize: '0.875rem' },
});

const features = tableFeatures({});
const columnHelper = createColumnHelper();

const columns = [
  columnHelper.accessor('key', { header: 'Key' }),
  columnHelper.accessor('value', { header: 'Value' }),
];

const data = [
  { key: 'NODE_ENV', value: 'production' },
  { key: 'PORT', value: '3000' },
];

function Demo() {
  const table = useTable({ features, data, columns });

  return <DataTable table={table} sx={custom.striped} />;
}

<Demo />;

API Reference

PropTypeDefaultDescription
tableTable<TFeatures, TData>—TanStack Table instance from useTable() (required)
toolbarReactNode—Slot rendered above the table
paginationReactNode—Slot rendered below the table
renderBody(rows: Row<TFeatures, TData>[]) => ReactNode—Replaces the default <Table.Body> with your own — see Performance
emptyStateReactNode—Content of one full-width row that shows when there are no rows
tablePropsOmit<TableProps, 'children'>—Props passed to the inner Table, for example contained
sortLabel(info) => string—Text of the sort button aria-label. info has column, label, nextDirection
selectionUseRowSelectionResult—Result of useRowSelection() — see Multi-Select
icons{ sortAscending?, sortDescending?, unsorted? }—Replaces the built-in icons. See the Icons guide
sxStyleXStyles—StyleX style override

Column meta

KeyTypeDefaultDescription
align'start' | 'center' | 'end''start'Alignment of the header and body cells
headerSxStyleXStyles—StyleX styles for the <th>
cellSxStyleXStyles—StyleX styles for the <td>
labelstring—Column name in the sort button label
selectionCellbooleanfalseMarks the checkbox column so selection gestures reach its cells

If renderBody returns undefined, DataTable renders the default body.

Note: @tanstack/react-table is an optional peer dependency with the range >=9.0.0 <10.0.0. Install it separately: bun add @tanstack/react-table.

Accessibility

  • Renders semantic <table>, <thead>, <tbody>, <th>, and <td> elements.
  • Sortable column headers set aria-sort (none, ascending, or descending). Each sort button has a label with the column name and the next direction.
  • The toolbar and pagination slots are outside the <table> element so they do not interfere with table semantics.

Performance

matix/ui does not guarantee performance for large collections (>100 items) without virtualization. DataTable renders every row from table.getRowModel().rows to the DOM by default, which is correct for the common case (< 100 rows) but costs paint time and memory at scale. For larger row counts, integrate a virtualization library like @tanstack/react-virtual.

The integration point is the renderBody render prop: it replaces the default <Table.Body> with one you build from the row model, so you can render only the virtualizer's visible subset while the header, toolbar, and pagination keep working. Table.Body, Table.Row, and Table.Cell accept style for exactly this case — dynamic computed values (the body's total height, each row's translateY offset) that CSS cannot express. Keep static styling in sx.

Caveat: in the example below the table root is the scroll container, so a toolbar or pagination would scroll away with the body, and the header is not sticky. Virtualized tables typically drop pagination (the virtualizer replaces it); if you need a fixed toolbar or sticky header alongside virtualization, place the toolbar outside <DataTable> and own the scroll element yourself via a wrapper.

Row virtualization with @tanstack/react-virtual

import { useRef } from 'react';
import * as stylex from '@stylexjs/stylex';
import {
  columnVisibilityFeature,
  createColumnHelper,
  flexRender,
  tableFeatures,
  useTable,
} from '@tanstack/react-table';
import { useVirtualizer } from '@tanstack/react-virtual';
import { DataTable } from '@matix/components/data-table';
import { Table } from '@matix/components/table';

const ROW_HEIGHT = 40; // px — must match the rendered row height

// Static layout styles go through sx; only per-frame computed values use `style`
const virtual = stylex.create({
  scroller: { height: '480px', overflowY: 'auto' },
  body: { display: 'grid', position: 'relative' },
  row: { display: 'flex', position: 'absolute', top: 0, left: 0, width: '100%' },
  cell: { display: 'flex', flexGrow: 1, flexBasis: 0, alignItems: 'center' },
});

interface Person {
  id: number;
  name: string;
  email: string;
}

const features = tableFeatures({ columnVisibilityFeature });
const columnHelper = createColumnHelper<typeof features, Person>();

const columns = columnHelper.columns([
  columnHelper.accessor('name', { header: 'Name' }),
  columnHelper.accessor('email', { header: 'Email' }),
]);

function VirtualizedDataTable({ data }: { data: Person[] }) {
  // DataTable forwards its ref to the root container — use it as the scroll element
  const scrollRef = useRef<HTMLDivElement>(null);

  const table = useTable({ features, data, columns });

  const virtualizer = useVirtualizer({
    count: table.getRowModel().rows.length,
    getScrollElement: () => scrollRef.current,
    estimateSize: () => ROW_HEIGHT,
    overscan: 10,
  });

  return (
    <DataTable
      ref={scrollRef}
      table={table}
      sx={virtual.scroller}
      renderBody={(rows) => (
        // Body sized to the full virtual height so the scrollbar reflects total rows
        <Table.Body sx={virtual.body} style={{ height: virtualizer.getTotalSize() }}>
          {virtualizer.getVirtualItems().map((virtualRow) => {
            const row = rows[virtualRow.index];
            return (
              <Table.Row
                key={row.id}
                selected={row.getIsSelected()}
                sx={virtual.row}
                style={{
                  height: virtualRow.size,
                  transform: `translateY(${virtualRow.start}px)`,
                }}
              >
                {row.getVisibleCells().map((cell) => (
                  <Table.Cell key={cell.id} sx={virtual.cell}>
                    {flexRender(cell.column.columnDef.cell, cell.getContext())}
                  </Table.Cell>
                ))}
              </Table.Row>
            );
          })}
        </Table.Body>
      )}
    />
  );
}
Rule: Virtualize when the row count exceeds 100. Below that, <DataTable table={table} /> renders all rows eagerly — the DOM overhead is negligible and you keep the default body (hover states, row selection) with zero extra code.