Ballmac UI home

Data Table

A complete data grid on TanStack Table: sortable headers, search, column visibility, row selection, pagination, a loading state and live result counts.

Status
INV-2045

Lumen Health

ops@lumen.example

Paid
$3,120.00
INV-2043

Harbor & Co

finance@harbor.example

Paid
$2,310.00
INV-2048

Quartz Media

billing@quartz.example

Overdue
$1,980.00
INV-2041

Northwind Studio

billing@northwind.example

Paid
$1,250.00
INV-2050

Sable Design

studio@sable.example

Pending
$1,105.00

1–5 of 10

Page 1 of 2

Installation

$ pnpm dlx shadcn@latest add @ballmac/data-table

Usage

import { DataTable, DataTableColumnHeader } from "@/components/ballmac/data-table"

The full example is in the Code tab above.

Examples

Loading and empty

NameRole

Loading…

Page 1 of 1
NameRole
No members yet. Invite your first teammate to get started.

0 results

Page 1 of 1

API reference

<DataTable>

PropTypeDefault
columns*

Column definitions from TanStack Table. Use `DataTableColumnHeader` in `header` for sortable columns, and `meta: { label: "Name" }` to name a column in the Columns menu.

ColumnDef<TData, TValue>[]—
data*

Rows to display.

TData[]—
label*

Accessible name of the table. Also names the scroll region.

string—
selectable

Add a leading checkbox column for selecting rows.

booleanfalse
onSelectionChange

Called with the selected row objects whenever the selection changes.

(rows: TData[]) => void—
searchable

Show a search field that filters across every column.

booleantrue
searchPlaceholder

Placeholder of the search field.

string—
columnToggle

Show a menu for hiding and showing columns.

booleantrue
pageSize

Rows per page. Set to 0 to disable pagination.

number8
loading

Show placeholder rows while data loads.

booleanfalse
emptyMessage

Message when there are no rows or no matches.

React.ReactNode—
initialSorting

Initial sort, for example `[{ id: "amount", desc: true }]`.

SortingState[]
toolbar

Extra content on the right of the toolbar, such as an export button.

React.ReactNode—
getRowId

Give every row a stable id. Defaults to the row index.

(row: TData, index: number) => string—
stickyHeader

Keep the header visible while the body scrolls. Combine with `maxHeightClassName`.

booleanfalse
maxHeightClassName

Height limit for the scroll area, for example `max-h-96`.

string—

<DataTableColumnHeader>

PropTypeDefault
column*

The column from the header context: `header: ({ column }) => <DataTableColumnHeader column={column} title="Amount" />`.

Column<TData, TValue>—
title*

Visible column title.

string—
numeric

Right-align the title for numeric columns.

boolean—

Also accepts the standard attributes of its root element.

Accessibility

KeyAction
Tab / EnterSort buttons, checkboxes, pagination and the column menu are real controls
Screen readersaria-sort on headers; the result count is a polite live region

Use with AI

Pass columns (TanStack ColumnDef) and data. Use DataTableColumnHeader for sortable headers. selectable adds checkboxes; pageSize sets rows per page. With the shadcn MCP server set up (guide), ask your agent:

Add the Ballmac UI Data Table (@ballmac/data-table) to this project with the shadcn MCP, then use it where it fits.

Use it for

  • Lists of records people search, sort and select
  • Admin and billing screens

Not for

  • A small static table; use table
  • Server-side paging for huge datasets without adapting the parts

Registry JSON: https://ui.ballmac.com/r/data-table.json

Credits

Based on shadcn/ui Data Table, adapted by Ballmac. Free to use in personal and commercial projects.