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.
function Table<Row>(props: TableProps<Row>): ElementType parameters
| Name | Description |
|---|---|
| Row |
Parameters
| Name | Type | Description |
|---|---|---|
| props | TableProps<Row> |
Returns
ElementProps
| Name | Type | Default | Description |
|---|---|---|---|
| caption? | ReactNode | A visible caption above the table: the part's title. | |
| className? | string | Extra classes on the root element. | |
| columns | readonly TableColumn<Row>[] | The columns, in order. | |
| defaultSort? | TableSort | null | The first order. Default: the rows as given. | |
| density? | 'default' | 'compact' | 'default' |
|
| detail? | (row: Row) => ReactNode | A row's detail. A row with one gets a caret that opens it under the row; | |
| filterBar? | TableFilterBar | A row of buttons above the table, "All (36)", "EU (9)", that keeps the rows of one value of a column. | |
| framed? | boolean | true | 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 | |
| rowEnd? | (row: Row) => ReactNode | Controls at the end of each row (a row's actions), in a last column of | |
| rowEndWidth? | number | The width of the | |
| 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. | |
| rows | readonly 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 | |
| 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. | |
| totalsAbove? | boolean | Show the |
Functions#
compareCellsFunction#
Compares two cell values for sorting: numbers as numbers, text in natural order, empty cells last.
function compareCells(a: TableCellValue, b: TableCellValue): numberParameters
| Name | Type | Description |
|---|---|---|
| a | TableCellValue | The first value. |
| b | TableCellValue | The second value. |
Returns
numberInterfaces#
TableColumnInterface#
One column of a Table.
interface TableColumn<Row>Type parameters
| Name | Description |
|---|---|
| Row |
Properties
| Name | Type | Description |
|---|---|---|
| filterable? | boolean | A select above the table keeps the rows whose raw value is the one picked. |
| id | string | Stable id. With no |
| label | string | The header text. |
| mono? | boolean | Ids, paths and codes: mono at the label size. Default: a text column whose every value
looks like |
| 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: |
TableFilterBarInterface#
A Table's filter bar: one button per value of a column, with its count.
interface TableFilterBarProperties
| Name | Type | Description |
|---|---|---|
| column | string | The column id. Its select filter is not offered. |
| onChange? | (value: string | null) => void | Called with the value picked, |
| value? | string | null | The value shown, controlled: |
TablePropsInterface#
Props for Table.
interface TableProps<Row>Type parameters
| Name | Description |
|---|---|
| Row |
Properties
| Name | Type | Default | Description |
|---|---|---|---|
| caption? | ReactNode | A visible caption above the table: the part's title. | |
| className? | string | Extra classes on the root element. | |
| columns | readonly TableColumn<Row>[] | The columns, in order. | |
| defaultSort? | TableSort | null | The first order. Default: the rows as given. | |
| density? | 'default' | 'compact' | 'default' |
|
| detail? | (row: Row) => ReactNode | A row's detail. A row with one gets a caret that opens it under the row; | |
| filterBar? | TableFilterBar | A row of buttons above the table, "All (36)", "EU (9)", that keeps the rows of one value of a column. | |
| framed? | boolean | true | 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 | |
| rowEnd? | (row: Row) => ReactNode | Controls at the end of each row (a row's actions), in a last column of | |
| rowEndWidth? | number | The width of the | |
| 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. | |
| rows | readonly 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 | |
| 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. | |
| totalsAbove? | boolean | Show the |
TableSortInterface#
The order of a Table's rows.
interface TableSortProperties
| Name | Type | Description |
|---|---|---|
| column | string | The column id. |
| direction | 'asc' | 'desc' |
|
Types#
TableCellValueType#
A cell's raw value: what a column sorts by and shows when it has no render.
type TableCellValue = string | number | null | undefined