Skip to content

components/Table

import { … } from 'zidane-ui'ui/src/components/Table.tsx

Components#

TableComponent#

Renders rows under a header, sortable by the columns that allow it. With search, filterable columns, pageSize or detail it also finds, narrows, pages and opens rows.

TypeScript
function Table<Row>(props: TableProps<Row>): Element
Type parameters
NameDescription
Row
Parameters
NameTypeDescription
propsTableProps<Row>

TableProps.

Element
Table props
NameTypeDefaultDescription
caption?ReactNode

A visible caption above the table: the part's title.

className?string

Extra classes on the root element.

columnsreadonly TableColumn<Row>[]

The columns, in order.

defaultSort?TableSort | null

The first order. Default: the rows as given.

density?'default' | 'compact''default'

compact sets cells in the metadata size with no row lines, for a dialog's facts.

detail?(row: Row) => ReactNode

A row's detail. A row with one gets a caret that opens it under the row; null for none.

filterBar?TableFilterBar

A row of buttons above the table, "All (36)", "EU (9)", that keeps the rows of one value of a column.

framed?booleantrue

Set in a tray. Off inside a surface that is already a tray.

highlight?(row: Row) => boolean

Rows to emphasize: an accent wash behind them, wherever the sort puts them.

label?string

Accessible name of the table (and of its scroll region).

maxHeight?string | number

Rows scroll past this height (a CSS length or pixels) under a header that stays put.

note?ReactNode

A key line under the caption, in the caption size's smaller muted text: what a color in the cells means.

onSortChange?(sort: TableSort) => void

Called with the next order when a sortable header is clicked.

pageSize?number

Rows on one page. More rows (after search and filters) get Previous and Next under the table, and the totals move to a line above the table.

rowEnd?(row: Row) => ReactNode

Controls at the end of each row (a row's actions), in a last column of rowEndWidth px that keeps its width whatever it holds, so nothing moves when they change. Give controls that only show on hover or focus the zg-reveal class: the row is their group.

rowEndWidth?number

The width of the rowEnd column, in px. Default: 144.

rowKey?(row: Row, index: number) => string | number

A row's stable key. Default: its index.

rowMenu?(row: Row) => readonly RowActionItem[]

The rows of a row's right-click menu. Absent or empty: the browser's own menu.

rowsreadonly Row[]

The rows, in their first order.

search?boolean

A search field above the table keeps the rows whose raw cell text holds the query (any case).

sort?TableSort | null

The order, controlled. Use it with onSortChange.

style?CSSProperties

Inline styles on the root element.

toolbarLead?ReactNode

Controls at the start of the toolbar line, before the filter bar, the search and the filters: the line wraps only when it has no room.

totals?(rows: readonly Row[]) => Partial<Record<string, ReactNode>> | null

A last row, by column id, from the rows after search and filters (every page). The first column shows the "Total" label when it has no total of its own. With more than one page the totals show as a line above the table instead. null: no row.

totalsAbove?boolean

Show the totals as figures above the table (the rows shown, then each total) even on one page: for a table the reader filters, so the figures follow the filter at a glance.

ui/src/components/Table.tsx:215

Functions#

compareCellsFunction#

Compares two cell values for sorting: numbers as numbers, text in natural order, empty cells last.

TypeScript
function compareCells(a: TableCellValue, b: TableCellValue): number
Parameters
NameTypeDescription
aTableCellValue

The first value.

bTableCellValue

The second value.

number

ui/src/components/Table.tsx:164

Interfaces#

TableColumnInterface#

One column of a Table.

TypeScript
interface TableColumn<Row>
TableColumn type parameters
NameDescription
Row
TableColumn properties
NameTypeDescription
filterable?boolean

A select above the table keeps the rows whose raw value is the one picked.

idstring

Stable id. With no value, also the key (or index, for an array row) the cell reads.

labelstring

The header text.

mono?boolean

Ids, paths and codes: mono at the label size. Default: a text column whose every value looks like ORD-1040 or starts with /.

numeric?boolean

Right-aligned, tabular figures, sorted as numbers.

render?(row: Row) => ReactNode

Draws the cell. Default: the raw value as text.

sortable?boolean

The header is a button that sorts by this column.

value?(row: Row) => TableCellValue

The cell's raw value. Default: row[id].

ui/src/components/Table.tsx:27

TableFilterBarInterface#

A Table's filter bar: one button per value of a column, with its count.

TypeScript
interface TableFilterBar
TableFilterBar properties
NameTypeDescription
columnstring

The column id. Its select filter is not offered.

onChange?(value: string | null) => void

Called with the value picked, null for every row.

value?string | null

The value shown, controlled: null (or a value not in the column) shows every row. Leave it out to let the table keep its own.

ui/src/components/Table.tsx:58

TablePropsInterface#

Props for Table.

TypeScript
interface TableProps<Row>
TableProps type parameters
NameDescription
Row
TableProps properties
NameTypeDefaultDescription
caption?ReactNode

A visible caption above the table: the part's title.

className?string

Extra classes on the root element.

columnsreadonly TableColumn<Row>[]

The columns, in order.

defaultSort?TableSort | null

The first order. Default: the rows as given.

density?'default' | 'compact''default'

compact sets cells in the metadata size with no row lines, for a dialog's facts.

detail?(row: Row) => ReactNode

A row's detail. A row with one gets a caret that opens it under the row; null for none.

filterBar?TableFilterBar

A row of buttons above the table, "All (36)", "EU (9)", that keeps the rows of one value of a column.

framed?booleantrue

Set in a tray. Off inside a surface that is already a tray.

highlight?(row: Row) => boolean

Rows to emphasize: an accent wash behind them, wherever the sort puts them.

label?string

Accessible name of the table (and of its scroll region).

maxHeight?string | number

Rows scroll past this height (a CSS length or pixels) under a header that stays put.

note?ReactNode

A key line under the caption, in the caption size's smaller muted text: what a color in the cells means.

onSortChange?(sort: TableSort) => void

Called with the next order when a sortable header is clicked.

pageSize?number

Rows on one page. More rows (after search and filters) get Previous and Next under the table, and the totals move to a line above the table.

rowEnd?(row: Row) => ReactNode

Controls at the end of each row (a row's actions), in a last column of rowEndWidth px that keeps its width whatever it holds, so nothing moves when they change. Give controls that only show on hover or focus the zg-reveal class: the row is their group.

rowEndWidth?number

The width of the rowEnd column, in px. Default: 144.

rowKey?(row: Row, index: number) => string | number

A row's stable key. Default: its index.

rowMenu?(row: Row) => readonly RowActionItem[]

The rows of a row's right-click menu. Absent or empty: the browser's own menu.

rowsreadonly Row[]

The rows, in their first order.

search?boolean

A search field above the table keeps the rows whose raw cell text holds the query (any case).

sort?TableSort | null

The order, controlled. Use it with onSortChange.

style?CSSProperties

Inline styles on the root element.

toolbarLead?ReactNode

Controls at the start of the toolbar line, before the filter bar, the search and the filters: the line wraps only when it has no room.

totals?(rows: readonly Row[]) => Partial<Record<string, ReactNode>> | null

A last row, by column id, from the rows after search and filters (every page). The first column shows the "Total" label when it has no total of its own. With more than one page the totals show as a line above the table instead. null: no row.

totalsAbove?boolean

Show the totals as figures above the table (the rows shown, then each total) even on one page: for a table the reader filters, so the figures follow the filter at a glance.

ui/src/components/Table.tsx:71

TableSortInterface#

The order of a Table's rows.

TypeScript
interface TableSort
TableSort properties
NameTypeDescription
columnstring

The column id.

direction'asc' | 'desc'

asc or desc.

ui/src/components/Table.tsx:50

Types#

TableCellValueType#

A cell's raw value: what a column sorts by and shows when it has no render.

TypeScript
type TableCellValue = string | number | null | undefined

ui/src/components/Table.tsx:24