Skip to content
SENVENLI UI

Data table

A Table with a toolbar: search, filters, a column picker, bulk actions, paging or virtualization, and its view kept in the URL.
Orders
import { DataTable } from "@senvenli/react/collection";

Examples

A server list

`query` fetches one page for the current view; the table shows loading, empty and error states itself.

Guidelines

When to use it

  • A record list people search, filter and act on in bulk: orders, customers, invoices.

Use something else when

  • A short, fixed list with no tools. Table

Accessibility

Keyboard

KeysWhat happens
Arrow keysMove between cells and rows.
TabMoves between the toolbar, the table and the pager.

Built in

  • Loading, empty, no-results and failed states have their own copy.
  • The selected count is announced in the bulk bar.

You provide

  • An aria-label, and labels for filters and bulk actions.

API reference

DataTable

aria-labelRequired
string

Names the table ("Orders").

columnsRequired
readonly DataTableColumn<T>[]
rowKey
(row: T) => Key

The row's stable id; row.id by default. Selection is kept by it across pages. Ids must be unique within the list; build one from the fields that are when the data has none (${row.date}:${row.channel}). A repeated id on a page still renders every row: the later ones are keyed a#2, a#3, … in row order, and selection, bulk actions and onRowAction receive those suffixed keys; a development warning names the repeated ids. A suffixed key follows the row's position, not the row: after a sort, filter or page change a selection made through it can move to another copy, and an id repeated on two pages is one key, so selecting it on one page selects it on both.

filters
readonly DataTableFilter[]
bulkActions
readonly DataTableBulkAction[]
defaultSort
SortDescriptor
columnVisibility
Readonly<Record<string, boolean>>

Column key → shown; columns left out are shown. Pass with onColumnVisibilityChange to own it.

onColumnVisibilityChange
(visibility: Record<string, boolean>) => void
onRowAction
(key: Key) => void

Opens the record (row press while nothing is selected).

pageSize
number

20 by default.

formatRange
(from: number, to: number, total: number) => string

The range sentence: (41, 60, 1204) → "41–60 of 1,204".

emptyState
React.ReactNode

What an empty list shows (with no search or filter active): an EmptyState size="small" with the action that fills it. "No records yet" by default.

view
DataTableView

The view (page, sort, search, filters), controlled. Keep it in the URL with useDataTableUrl, or anywhere else; left out, the table keeps it itself.

defaultView
Partial<DataTableView>

The first view when uncontrolled: page 1, the default sort, no search and no filters by default.

onViewChange
(view: DataTableView) => void

Called with the whole next view on every change (a new sort, search, filter or page).

density
Density

compact (36px rows) by default: DataTable is the dense working list of a back office.

query
(view: DataTableQuery, signal: AbortSignal) => Promise<DataTableResult<T>>

A server list: fetches one page for the view; aborted when the view changes again. It is read when the view changes, not when the function does: for a list that depends on something else (a parent tab), give the DataTable a key from it so it starts afresh.

rows
readonly T[]

A client list: searched, filtered and sorted here; paged, or virtualized when long.

virtualizeAbove
number

Client lists longer than this render only the rows in view instead of pages. 200 by default.

height
number

The virtualized list's height in px. 480 by default.