Skip to content
Ballpoint

Data Table

A table of records with search, sorting, paging, tick boxes and a menu to hide columns. The Table with a little state in front of it; no table library.

From shadcn/ui
Payments
successken99@example.com$316.00
successabe45@example.com$242.00
processingmonserrat44@example.com$837.00
successsilas22@example.com$874.00
failedcarmella@example.com$721.00
0 of 8 rows selected.
Page 1 of 2

Installation

pnpm dlx shadcn@latest add @ballpoint/data-table

Usage

tsx
import { DataTable, type DataTableColumn } from "@/components/ui/data-table"

const columns: DataTableColumn<Payment>[] = [
  { id: "email", header: "Email", sortable: true },
  { id: "amount", header: "Amount", sortable: true, align: "right" },
]

<DataTable columns={columns} data={payments} search selectable />

Examples

Sorting only

No toolbar and no paging, opening sorted by one column.

CharcoalCharcoal3
Felt tipInk1.2
HB pencilGraphite0.9
Blue ballpointInk0.7
Black gelInk0.5

Row actions

A menu on every row; the data is yours, so removing a row is a state change.

EditedActions
Letter to AdaToday
Margin sketchesYesterday
Shopping listMonday

API reference

columns
DataTableColumn<T>[]

id (the row's field), header, and optionally accessor, cell, sortable, searchable, hideable, align.

data
T[]

The rows.

getRowId
default index
(row, index) => string

A stable key for each row. Needed to keep selection when data changes.

pageSize
default 10
number | false

Rows to a page, or false for no paging.

search
default false
boolean | string

A search field over every searchable column. A string sets its placeholder.

selectable / onSelectionChange
default false
boolean / (rows: T[]) => void

A tick box on every row and one for the page, and what is ticked.

columnMenu
default false
boolean

A Columns menu to hide and show columns.

defaultSort
{ id: string; dir: 'asc' | 'desc' }

How it opens.

toolbar / empty / caption
ReactNode / ReactNode / string

More for the bar above; what to say when no row matches; a name for screen readers.