DataTable
DataTable is a 2-dimensional data structure where each row is an item, and each column is a data point about the item.
Page navigation navigation
React examples
Default
Repositories
Repository | Type | Updated | Dependabot | Code scanning |
---|---|---|---|---|
codeql-dca-worker | Internal | Alerts | Report secrets | |
aegir | Public | Alerts | Report secrets | |
strapi | Public | |||
codeql-ci-nightlies | Public | Alerts | ||
dependabot-updates | Public | |||
tsx-create-react-app | Public | |||
bootstrap | Public | Alerts | ||
docker-templates | Public | Alerts |
With custom column widths
Repositories
grow w/ 200px max | growCollapse w/ 100px min | auto | 200px | undefined (defaults to grow) |
---|---|---|---|---|
codeql-dca-worker | Internal | Alerts | Report secrets | |
aegir | Public | Alerts | Report secrets | |
strapi | Public | |||
codeql-ci-nightlies | Public | Alerts | ||
dependabot-updates | Public | |||
tsx-create-react-app | Public | |||
bootstrap | Public | Alerts | ||
docker-templates | Public | Alerts |
Columns text alignment
- Left (default): Follows natural reading direction in right-to-left writing systems.
- Right-aligned columns are used for numbers and other data that is best represented right-aligned.
In this example, there is a "Pull requests" column that is right-aligned to make it easier to visually scan and compare the numbers.
Repositories
Repository | Pull requests | Type | Updated |
---|---|---|---|
codeql-dca-worker | 12 | Internal | |
aegir | 34 | Public | |
strapi | 8 | Public | |
codeql-ci-nightlies | 1 | Public | |
dependabot-updates | 57 | Public | |
tsx-create-react-app | 35 | Public | |
bootstrap | 42 | Public | |
docker-templates | 3 | Public |
Table cell density
- Condensed: Maximizes data visibility in a small area.
- Normal (default): Balances data display with whitespace for clarity.
- Spacious: Enhances readability for dense or complex content.
This example uses 'spacious'
table cell padding.
Repositories
Repository | Type | Updated | Dependabot | Code scanning |
---|---|---|---|---|
codeql-dca-worker | Internal | Alerts | Report secrets | |
aegir | Public | Alerts | Report secrets | |
strapi | Public | |||
codeql-ci-nightlies | Public | Alerts | ||
dependabot-updates | Public | |||
tsx-create-react-app | Public | |||
bootstrap | Public | Alerts | ||
docker-templates | Public | Alerts |
Sort rows by column data
If a table is sortable, one column must be sorted by default. Clicking a sorted column toggles between ascending and descending; unsorted columns sort in ascending order on first click.
In this example, the rows are sortable by "Repository" and "Updated" column data.
Repositories
Type | Dependabot | Code scanning | ||
---|---|---|---|---|
codeql-dca-worker | Internal | Alerts | Report secrets | |
aegir | Public | Alerts | Report secrets | |
strapi | Public | |||
codeql-ci-nightlies | Public | Alerts | ||
dependabot-updates | Public | |||
tsx-create-react-app | Public | |||
bootstrap | Public | Alerts | ||
docker-templates | Public | Alerts |
With title and subtitle
Repositories
A subtitle could appear here to give extra context to the data.
Repository | Type | Updated | Dependabot | Code scanning |
---|---|---|---|---|
codeql-dca-worker | Internal | Alerts | Report secrets | |
aegir | Public | Alerts | Report secrets | |
strapi | Public | |||
codeql-ci-nightlies | Public | Alerts | ||
dependabot-updates | Public | |||
tsx-create-react-app | Public | |||
bootstrap | Public | Alerts | ||
docker-templates | Public | Alerts |
With table action
Repositories
A subtitle could appear here to give extra context to the data.
Repository | Type | Updated | Dependabot | Code scanning |
---|---|---|---|---|
codeql-dca-worker | Internal | Alerts | Report secrets | |
aegir | Public | Alerts | Report secrets | |
strapi | Public | |||
codeql-ci-nightlies | Public | Alerts | ||
dependabot-updates | Public | |||
tsx-create-react-app | Public | |||
bootstrap | Public | Alerts | ||
docker-templates | Public | Alerts |
With single row action
Actions that affect the item represented in the row are placed in the last column, and they don't require a visible column header.
Repositories
Repository | Type | Updated | Dependabot | Code scanning | Actions |
---|---|---|---|---|---|
codeql-dca-worker | Internal | Alerts | Report secrets | ||
aegir | Public | Alerts | Report secrets | ||
strapi | Public | ||||
codeql-ci-nightlies | Public | Alerts | |||
dependabot-updates | Public | ||||
tsx-create-react-app | Public | ||||
bootstrap | Public | Alerts | |||
docker-templates | Public | Alerts |
With multiple row actions
If you have multiple actions for a row, start by pulling them into a dropdown menu.
If one of the actions is heavily used, pull it out for easier access. Do not pull out more than 1 action.
Row actions in a dropdown
Repository | Type | Updated | Dependabot | Code scanning | Actions |
---|---|---|---|---|---|
codeql-dca-worker | Internal | Alerts | Report secrets | ||
aegir | Public | Alerts | Report secrets | ||
strapi | Public |
Row actions inline
Repository | Type | Updated | Dependabot | Code scanning | Actions |
---|---|---|---|---|---|
codeql-dca-worker | Internal | Alerts | Report secrets | ||
aegir | Public | Alerts | Report secrets | ||
strapi | Public |
Row actions overflowing
Repository | Type | Updated | Dependabot | Code scanning | Actions |
---|---|---|---|---|---|
codeql-dca-worker | Internal | Alerts | Report secrets | ||
aegir | Public | Alerts | Report secrets | ||
strapi | Public |
With paginated rows
The pagination footer shows the user where they are in relation to the total number of rows and provides controls for navigating all rows.
Guidelines on when to paginate rows
Repositories
Repository | Type | Updated | Dependabot | Code scanning |
---|---|---|---|---|
Repository 1 | Internal | |||
Repository 2 | Public | |||
Repository 3 | Public | |||
Repository 4 | Internal | |||
Repository 5 | Public | |||
Repository 6 | Public | |||
Repository 7 | Internal | |||
Repository 8 | Public | |||
Repository 9 | Public | |||
Repository 10 | Internal |
In a loading state
DataTables use "skeleton" loading states to indicate loading content.
Repositories
Repository | Type | Updated | Dependabot | Code scanning |
---|---|---|---|---|
Loading | Loading | Loading | Loading | Loading |
More code examples
The previous examples are a curated subset of the full capabilities of the DataTable
component. For more examples, see the DataTable Storybook stories.
Props
DataTable
Name | Required | Description |
---|---|---|
aria-describedby | string Provide an id to an element which uniquely describes this table | |
aria-labelledby | string Provide an id to an element which uniquely labels this table | |
data | Array<Data> Provide a collection of the rows which will be rendered inside of the table | |
columns | Array<Column<Data>> Provide the columns for the table and the fields in `data` to which they correspond | |
cellPadding | 'condensed' | 'normal' | 'spacious' Specify the amount of space that should be available around the contents of a cell | |
aria-describedby | string Provide an id to an element which uniquely describes this table | |
aria-labelledby | string Provide an id to an element which uniquely labels this table | |
initialSortColumn | string | number Provide the id or field of the column by which the table is sorted. When
using this `prop`, the input data must be sorted by this column in
ascending order | |
initialSortDirection | 'ASC' | 'DESC' Provide the sort direction that the table should be sorted by on the
currently sorted column |
Table
Name | Required | Description |
---|---|---|
aria-describedby | string Provide an id to an element which uniquely describes this table | |
aria-labelledby | string Provide an id to an element which uniquely labels this table | |
children | React.ReactNode | |
cellPadding | 'condensed' | 'normal' | 'spacious' Specify the amount of space that should be available around the contents of a cell |
Table.Head
Name | Required | Description |
---|---|---|
children | React.ReactNode |
Table.Actions
Name | Required | Description |
---|---|---|
children | React.ReactNode |
Table.Body
Name | Required | Description |
---|---|---|
children | React.ReactNode |
Table.Row
Name | Required | Description |
---|---|---|
children | React.ReactNode |
Table.Header
Name | Required | Description |
---|---|---|
align | 'end' | 'start' The horizontal alignment of the cell's content | |
children | React.ReactNode |
Table.Cell
Name | Required | Description |
---|---|---|
align | 'end' | 'start' The horizontal alignment of the cell's content | |
children | React.ReactNode | |
scope | 'row' Provide the scope for a table cell, useful for defining a row header using `scope="row"` |
Table.CellPlaceholder
Name | Required | Description |
---|
Table.Container
Name | Required | Description |
---|---|---|
children | React.ReactNode |
Table.Divider
Name | Required | Description |
---|
Table.Title
Name | Required | Description |
---|---|---|
children | React.ReactNode | |
id | Required | string Provide a unique id for the table subtitle. This should be used along with
`aria-labelledby` on `DataTable` |
Table.Subtitle
Name | Required | Description |
---|---|---|
children | React.ReactNode | |
id | Required | string Provide a unique id for the table subtitle. This should be used along with
`aria-describedby` on `DataTable` |
Table.Skeleton
Name | Required | Description |
---|---|---|
cellPadding | 'condensed' | 'normal' | 'spacious' Specify the amount of space that should be available around the contents of a cell | |
columns | Required | Array<Column<Data>> |
rows | number Optionally specify the number of rows which should be included in the skeleton state of the component |
Table.Pagination
Name | Required | Description |
---|---|---|
aria-label | Required | string Defines a string value that labels the current element.
Provide a label for the navigation landmark rendered by this component
@see aria-labelledby. |
defaultPageIndex | string Provide an optional index to specify the default selected page | |
id | string Optionally provide an `id` that is placed on the navigation landmark
rendered by this component | |
onChange | ({ pageIndex }: { pageIndex: number }) => void Optionally provide a handler that is called whenever the pagination state
is updated | |
pageSize | number Optionally specify the number of items within a page | |
totalCount | Required | number Specify the total number of items within the collection |
showPages | boolean | { narrow?: boolean; regular?: boolean; wide?: boolean; } Whether to show the page numbers |
Table.ErrorDialog
Name | Required | Description |
---|---|---|
children | Required | React.ReactNode The content of the dialog. This is usually a message explaining the error. |
title | string The title of the dialog. This is usually a short description of the error. | |
onRetry | () => void Event handler called when the user clicks the retry button. | |
onDismiss | () => void Event handler called when the dialog is dismissed. |
Table.SortHeader
Name | Required | Description |
---|---|---|
direction | Required | 'ASC' | 'DESC' | 'NONE' Specify the sort direction for the TableHeader |
onToggleSort | Required | () => void Provide a handler that is called when the sortable TableHeader is
interacted with via a click or keyboard interaction |
align | 'end' | 'start' The horizontal alignment of the cell's content |
Column options
Name | Required | Description |
---|---|---|
align | 'start' | 'end' The horizontal alignment of the column's content | |
field | ObjectPaths<Data> Optionally provide a field to render for this column. This may be the key of the object or a string that accesses nested objects through `.`. For example: `field: a.b.c`
Alternatively, you may provide a `renderCell` for this column to render the field in a row | |
header | Required | string | (() => React.ReactNode) Provide the name of the column. This will be rendered as a table header within the table itself |
maxWidth | React.CSSProperties['maxWidth'] The maximum width the column can grow to | |
minWidth | React.CSSProperties['minWidth'] The minimum width the column can grow to | |
renderCell | (data: Data) => React.ReactNode Provide a custom component or render prop to render the data for this column in a row | |
rowHeader | boolean Specify if the value of this column for a row should be treated as a row header | |
sortBy | boolean | 'alphanumeric' | 'basic' | 'datetime' | (a: Data, b: Data) => number Specify if the table should sort by this column and, if applicable, a specific sort strategy or custom sort strategy | |
width | 'grow' | 'growCollapse' | 'auto' | React.CSSProperties['width'] Controls the width of the column.
- 'grow': Stretch to fill available space, and min width is the width of the widest cell in the column
- 'growCollapse': Stretch to fill available space or shrink to fit in the available space. Allows the column to shrink smaller than the cell content's width.
- 'auto': The column is the width of it’s widest cell. Not intended for use with columns who’s content length varies a lot because a layout shift will occur when the content changes
- explicit width: Will be exactly that width and will not grow or shrink to fill the parent |