Live example
Implementation
Tables are made of a series of sub-components:
Caption
Use a caption to give the table context. It helps accessibility as it will be read out by screenreaders. You can put a heading in a caption.
Table Heading
Use a table heading to describe the general content of the data table.
Row headers
- Use row headers to describe the data.
- Row headers can also be react elements, allowing greater customisation.
Separator rows
From versions 3.4.0 (web) and 3.5.0 (native), it is possible to add separator rows in order to break down data into groups as desired. These are added in as items as per the API described in the Properties below.
Striped rows
Striping is the background zebra-striping on rows, not the separating lines. You can enable or disable striping for the entire table. It is enabled by default.
Column width
On web you can optionally assign a fixed width to columns.
Widths are required on Native. Passing auto for width on Native will set the flex property to 1, allowing it to stretch.
Properties
DataTable
|
Name |
Values |
Default |
|---|---|---|
|
items |
ReactNode[][] | SeparatorCellData[][] |
|
|
columnHeadings |
ReactNode[] |
|
|
caption |
ReactNode |
|
|
containerAriaLabel |
string |
|
|
rowHeadings |
boolean |
|
|
columnWidths |
string[] |
|
|
striped |
boolean |
true |
|
title |
string |
|
|
key |
React.key | null |
|
|
stackOnMobile |
boolean |
|
|
... |
JSX.IntrinsicElements["table"] |
|
SeparatorCell
|
Name |
Values |
Default |
|---|---|---|
|
colSpan |
number |
|
|
key |
React.Key | null |
|
|
… |
JSX.IntrinsicElements["td"] |
|
TableBody
|
Name |
Values |
Default |
|---|---|---|
|
... |
JSX.IntrinsicElements["tbody"] |
|
TableCaption
|
Name |
Values |
Default |
|---|---|---|
|
... |
JSX.IntrinsicElements["caption"] |
|
TableCell
|
Name |
Values |
Default |
|---|---|---|
|
cellWidth |
string |
|
|
... |
JSX.IntrinsicElements["td"] |
|
TableColumnHeader
|
Name |
Values |
Default |
|---|---|---|
|
columnWdith |
string |
|
|
... |
JSX.IntrinsicElements["th"] |
|
TableHead
|
Name |
Values |
Default |
|---|---|---|
|
... |
JSX.IntrinsicElements["thead"] |
|
TableRow
|
Name |
Values |
Default |
|---|---|---|
|
striped |
boolean |
false |
|
... |
JSX.IntrinsicElements["tr"] |
|
TableRowHeader
|
Name |
Values |
Default |
|---|---|---|
|
cellWidth |
string |
|
|
... |
JSX.IntrinsicElements["th"] |
|
Native Properties
Data Table
|
Name |
Values |
Default |
|---|---|---|
|
rowHeadings |
boolean |
false |
|
striped |
boolean |
false |
|
columnWidths (required) |
string[] |
|
|
data |
Item[] |
|
|
index |
number |
|
TableRow
|
Name |
Values |
Default |
|---|---|---|
|
items (required) |
Item[][] |
|
Composition
- Cell
- Cell content
|
Tokens |
|
|---|---|
|
Cell border colour |
color.surface.borderdim |
|
Cell background colour - Surface, surface dim |
color.surface.surface color.surface.dim |
|
Separator row background colour |
color.surface.bright |
|
Border width |
boder.width.sm |
|
Padding |
space-200 space-250 |