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 | |
|---|---|---|---|---|---|
| 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 | |
|---|---|---|---|---|---|
| codeql-dca-worker | Internal | Alerts | Report secrets | ||
| aegir | Public | Alerts | Report secrets | ||
| strapi | Public |
Row actions inline
| Repository | Type | Updated | Dependabot | Code scanning | |
|---|---|---|---|---|---|
| codeql-dca-worker | Internal | Alerts | Report secrets | ||
| aegir | Public | Alerts | Report secrets | ||
| strapi | Public |
Row actions overflowing
| Repository | Type | Updated | Dependabot | Code scanning | |
|---|---|---|---|---|---|
| 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 | Default | Description |
|---|---|---|
aria-describedby | stringProvide an id to an element which uniquely describes this table | |
aria-labelledby | stringProvide 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 | |
cellPadding | 'condensed' | 'normal' | 'spacious'Specify the amount of space that should be available around the contents of a cell | |
aria-describedby | stringProvide an id to an element which uniquely describes this table | |
aria-labelledby | stringProvide an id to an element which uniquely labels this table | |
initialSortColumn | string | numberProvide the id or field of the column by which the table is sorted. When
using this | |
initialSortDirection | 'ASC' | 'DESC'Provide the sort direction that the table should be sorted by on the currently sorted column | |
onToggleSort | (columnId: ObjectPaths<Data> | string | number, direction: 'ASC' | 'DESC') => voidFires every time the user clicks a sortable column header. It reports the column id that is now sorted and the direction after the toggle (never 'NONE'). |
Table
| Name | Default | Description |
|---|---|---|
aria-describedby | stringProvide an id to an element which uniquely describes this table | |
aria-labelledby | stringProvide 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 | Default | Description |
|---|---|---|
children | React.ReactNode |
Table.Actions
| Name | Default | Description |
|---|---|---|
children | React.ReactNode |
Table.Body
| Name | Default | Description |
|---|---|---|
children | React.ReactNode |
Table.Row
| Name | Default | Description |
|---|---|---|
children | React.ReactNode |
Table.Header
| Name | Default | Description |
|---|---|---|
align | 'end' | 'start'The horizontal alignment of the cell's content | |
children | React.ReactNode |
Table.Cell
| Name | Default | 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 |
Table.CellPlaceholder
Table.Container
| Name | Default | Description |
|---|---|---|
children | React.ReactNode |
Table.Divider
Table.Title
| Name | Default | Description |
|---|---|---|
children | React.ReactNode | |
id Required | stringProvide a unique id for the table subtitle. This should be used along with
|
Table.Subtitle
| Name | Default | Description |
|---|---|---|
children | React.ReactNode | |
id Required | stringProvide a unique id for the table subtitle. This should be used along with
|
Table.Skeleton
| Name | Default | Description |
|---|---|---|
cellPadding | normal | 'condensed' | 'normal' | 'spacious'Specify the amount of space that should be available around the contents of a cell |
columns Required | Array<Column<Data>> | |
rows | 10 | numberOptionally specify the number of rows which should be included in the skeleton state of the component |
Table.Pagination
| Name | Default | Description |
|---|---|---|
aria-label Required | stringDefines a string value that labels the current element. Provide a label for the navigation landmark rendered by this component @see aria-labelledby. | |
defaultPageIndex | stringProvide an optional index to specify the default selected page | |
id | stringOptionally provide an | |
onChange | ({ pageIndex }: { pageIndex: number }) => voidOptionally provide a handler that is called whenever the pagination state is updated | |
pageSize | 25 | numberOptionally specify the number of items within a page |
totalCount Required | numberSpecify the total number of items within the collection | |
showPages | {narrow: false} | boolean | { narrow?: boolean; regular?: boolean; wide?: boolean; }Whether to show the page numbers |
Table.ErrorDialog
| Name | Default | Description |
|---|---|---|
children Required | React.ReactNodeThe content of the dialog. This is usually a message explaining the error. | |
title | 'Error' | stringThe title of the dialog. This is usually a short description of the error. |
onRetry | () => voidEvent handler called when the user clicks the retry button. | |
onDismiss | () => voidEvent handler called when the dialog is dismissed. |
Table.SortHeader
| Name | Default | Description |
|---|---|---|
direction Required | 'ASC' | 'DESC' | 'NONE'Specify the sort direction for the TableHeader | |
onToggleSort Required | () => voidProvide 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 | Default | 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 | |
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.ReactNodeProvide a custom component or render prop to render the data for this column in a row | |
rowHeader | booleanSpecify 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) => numberSpecify if the table should sort by this column and, if applicable, a specific sort strategy or custom sort strategy | |
width | 'grow' | 'grow' | 'growCollapse' | 'auto' | React.CSSProperties['width']Controls the width of the column.
|