Data table
Data table is a 2-dimensional data structure where each row is an item, and each column is a data point about the item.
On this page
- @primer/react@37.6.0
- Alpha
- Reviewed for accessibility
On this page
Import
import {DataTable} from '@primer/react/experimental'
Examples
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 |
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 | |
idRequired | stringProvide a unique id for the table subtitle. This should be used along with
|
Table.Subtitle
| Name | Default | Description |
|---|---|---|
children | React.ReactNode | |
idRequired | 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 |
columnsRequired | 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-labelRequired | 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 |
totalCountRequired | 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 |
|---|---|---|
childrenRequired | 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 |
|---|---|---|
directionRequired | 'ASC' | 'DESC' | 'NONE'Specify the sort direction for the TableHeader | |
onToggleSortRequired | () => 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 | |
headerRequired | 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.
|