Data views
Main DataTable pageThere are currently two built-in options for displaying the data DataTable.Table
and CardView
, but you can also build your own.
DataTable.Table
The Table
component is meant to be rendered within a DataTableContext
(provided by DataTable
here).
It displays the data provided by the DataTableContext
as an html table.
- Defaultnull
caption
string
|element
className
string
data
shape
{}[]
Requiredspecifies the order and contents of the table's columns and provides display strings for each column's heading. It is composed of an ordered array of objects. Each object contains the following keys:
label
(string or element; required) contains the display string for each column's heading.key
(string; required) maps that label to its corresponding datum for each row indata
, to ensure table data are displayed in their appropriate columns.columnSortable
(boolean; optional) specifies at the column-level whether the column is sortable. IfcolumnSortable
istrue
, a sort button will be rendered in the column table heading. It is only required iftableSortable
is set totrue
.onSort
(function; conditionally required) specifies what function is called when a sortable column is clicked. It is only required if the column'scolumnSortable
is set totrue
.hideHeader
(boolean; optional) specifies at the column-level whether the column label is visible. A column that is sortable cannot have its label be hidden.width
(string; conditionally required) only ifhasFixedColumnWidths
is set totrue
, the<td>
elements'class
attributes will be set to this value. This allows restricting columns to specific widths. See Bootstrap's grid documentation forcol
class names that can be used.
The order of objects in
columns
specifies the order of the columns in the table.columns
shape
{key:string
Required,label:string
|element
Required,columnSortable:isRequiredIf(PropTypes.bool, props => props.tableSortable)
,onSort:isRequiredIf(PropTypes.func, props => props.columnSortable)
,hideHeader:bool
,width:}isRequiredIf(PropTypes.string, props => props.hasFixedColumnWidths)
,[]
Requiredspecifies the order and contents of the table's columns and provides display strings for each column's heading. It is composed of an ordered array of objects. Each object contains the following keys:
label
(string or element; required) contains the display string for each column's heading.key
(string; required) maps that label to its corresponding datum for each row indata
, to ensure table data are displayed in their appropriate columns.columnSortable
(boolean; optional) specifies at the column-level whether the column is sortable. IfcolumnSortable
istrue
, a sort button will be rendered in the column table heading. It is only required iftableSortable
is set totrue
.onSort
(function; conditionally required) specifies what function is called when a sortable column is clicked. It is only required if the column'scolumnSortable
is set totrue
.hideHeader
(boolean; optional) specifies at the column-level whether the column label is visible. A column that is sortable cannot have its label be hidden.width
(string; conditionally required) only ifhasFixedColumnWidths
is set totrue
, the<td>
elements'class
attributes will be set to this value. This allows restricting columns to specific widths. See Bootstrap's grid documentation forcol
class names that can be used.
The order of objects in
columns
specifies the order of the columns in the table.headingClassName
string
[]
Default[]Specifies Bootstrap class names to apply to the table heading. Options are detailed in Bootstrap's docs.
tableSortable
bool
DefaultfalseSpecifies whether the table is sortable. This setting supercedes column-level sortability, so if it is
false
, no sortable components will be rendered.hasFixedColumnWidths
bool
DefaultfalseSpecifies whether the table's columns have fixed widths. Every element in
columns
must define awidth
if this istrue
.defaultSortedColumn
isRequiredIf(PropTypes.string, props => props.tableSortable)
Specifies the key of the column that is sorted by default. It is only required if
tableSortable
is set totrue
.defaultSortDirection
isRequiredIf(PropTypes.string, props => props.tableSortable)
Specifies the direction the
defaultSortedColumn
is sorted in by default; it will typically be either 'asc' or 'desc'. It is only required iftableSortable
is set totrue
.sortButtonsScreenReaderText
isRequiredIf( PropTypes.shape({ asc: PropTypes.string, desc: PropTypes.string, defaultText: PropTypes.string, }), props => props.tableSortable, )
Default{ asc: 'sort ascending', desc: 'sort descending', defaultText: 'click to sort', }Specifies the screen reader only text that accompanies the sort buttons for sortable columns. It takes the form of an object containing the following keys:
asc
: (string) specifies the screen reader only text for sort buttons in the ascending state.desc
: (string) specifies the screen reader only text for sort buttons in the descending state.defaultText
: (string) specifies the screen reader only text for sort buttons that are not engaged.
It is only required if
tableSortable
is set totrue
.Default:
{asc: 'sort ascending',desc: 'sort descending',defaultText: 'click to sort',}rowHeaderColumnKey
string
Specifies the key for the column that should act as a row header. Rather than rendering as
<td>
elements, cells in this column will render as<th scope="row">
Table Subcomponents
Subcomponents of DataTable.Table
can be used independently of the main component. They are designed for use with a react-table
instance.
row
shape
{getRowProps:func
Required,cells:shape
{}[]
Required,id:string
Required,isSelected:bool
,isExpanded:} Requiredbool
,Row data that is received from
react-table
API.
getCellProps
func
RequiredProps for the td element
render
func
RequiredFunction that renders the cell contents. Will be called with the string 'Cell'
column
shape
{cellClassName:} Requiredstring
,Table column
getHeaderProps
func
RequiredReturns props for the th element
isSorted
bool
DefaultfalseIndicates whether or not a column is sorted
render
func
RequiredRenders the header content. Passed the string 'Header'
isSortedDesc
bool
DefaultfalseIndicates whether the column is sorted in descending order
getSortByToggleProps
func
Default() => {}Gets props related to sorting that will be passed to th
canSort
bool
DefaultfalseIndicates whether a column is sortable
headerClassName
string
DefaultnullClass(es) to be applied to header cells
headerGroups
shape
{headers:shape
{getHeaderProps:}func
Required,[]
Required,getHeaderGroupProps:}func
Required,[]
Required
CardView and alternate table components
You may choose to use any table component by using the following code in your display component:
const instance = useContext(DataTableContext)
The CardView takes a CardComponent
that is personalized to the table in question and displays
a responsive grid of cards.
Sample Card component for use with CardView
The CardComponent
prop on CardView
represents a table row, and will receive the row that react-table
provides as props.
className
string
Default''The class name for the CardGrid component
columnSizes
shape
{xs:number
,sm:number
,md:number
,lg:number
,xl:}number
,Default{ xs: 12, lg: 6, xl: 4, }An object containing the desired column size at each breakpoint, following a similar props API as
react-bootstrap/Col
CardComponent
func
RequiredYour card component must be individualized to your table. It will be called with props from the "row" of data it will display
const MiyazakiCard = ({ className, original }) => {const { title, director, release_date } = original;return (<Card className={className}><Card.ImageCap src="https://source.unsplash.com/360x200/?nature,flower" /><Card.Section title={title}><dl><dt>Director</dt><dd>{director}</dd><dt>Release Date</dt><dd>{release_date}</dd></dl></Card.Section></Card>);};
- Defaultnull
caption
string
|element
className
string
data
shape
{}[]
Requiredspecifies the order and contents of the table's columns and provides display strings for each column's heading. It is composed of an ordered array of objects. Each object contains the following keys:
label
(string or element; required) contains the display string for each column's heading.key
(string; required) maps that label to its corresponding datum for each row indata
, to ensure table data are displayed in their appropriate columns.columnSortable
(boolean; optional) specifies at the column-level whether the column is sortable. IfcolumnSortable
istrue
, a sort button will be rendered in the column table heading. It is only required iftableSortable
is set totrue
.onSort
(function; conditionally required) specifies what function is called when a sortable column is clicked. It is only required if the column'scolumnSortable
is set totrue
.hideHeader
(boolean; optional) specifies at the column-level whether the column label is visible. A column that is sortable cannot have its label be hidden.width
(string; conditionally required) only ifhasFixedColumnWidths
is set totrue
, the<td>
elements'class
attributes will be set to this value. This allows restricting columns to specific widths. See Bootstrap's grid documentation forcol
class names that can be used.
The order of objects in
columns
specifies the order of the columns in the table.columns
shape
{key:string
Required,label:string
|element
Required,columnSortable:isRequiredIf(PropTypes.bool, props => props.tableSortable)
,onSort:isRequiredIf(PropTypes.func, props => props.columnSortable)
,hideHeader:bool
,width:}isRequiredIf(PropTypes.string, props => props.hasFixedColumnWidths)
,[]
Requiredspecifies the order and contents of the table's columns and provides display strings for each column's heading. It is composed of an ordered array of objects. Each object contains the following keys:
label
(string or element; required) contains the display string for each column's heading.key
(string; required) maps that label to its corresponding datum for each row indata
, to ensure table data are displayed in their appropriate columns.columnSortable
(boolean; optional) specifies at the column-level whether the column is sortable. IfcolumnSortable
istrue
, a sort button will be rendered in the column table heading. It is only required iftableSortable
is set totrue
.onSort
(function; conditionally required) specifies what function is called when a sortable column is clicked. It is only required if the column'scolumnSortable
is set totrue
.hideHeader
(boolean; optional) specifies at the column-level whether the column label is visible. A column that is sortable cannot have its label be hidden.width
(string; conditionally required) only ifhasFixedColumnWidths
is set totrue
, the<td>
elements'class
attributes will be set to this value. This allows restricting columns to specific widths. See Bootstrap's grid documentation forcol
class names that can be used.
The order of objects in
columns
specifies the order of the columns in the table.headingClassName
string
[]
Default[]Specifies Bootstrap class names to apply to the table heading. Options are detailed in Bootstrap's docs.
tableSortable
bool
DefaultfalseSpecifies whether the table is sortable. This setting supercedes column-level sortability, so if it is
false
, no sortable components will be rendered.hasFixedColumnWidths
bool
DefaultfalseSpecifies whether the table's columns have fixed widths. Every element in
columns
must define awidth
if this istrue
.defaultSortedColumn
isRequiredIf(PropTypes.string, props => props.tableSortable)
Specifies the key of the column that is sorted by default. It is only required if
tableSortable
is set totrue
.defaultSortDirection
isRequiredIf(PropTypes.string, props => props.tableSortable)
Specifies the direction the
defaultSortedColumn
is sorted in by default; it will typically be either 'asc' or 'desc'. It is only required iftableSortable
is set totrue
.sortButtonsScreenReaderText
isRequiredIf( PropTypes.shape({ asc: PropTypes.string, desc: PropTypes.string, defaultText: PropTypes.string, }), props => props.tableSortable, )
Default{ asc: 'sort ascending', desc: 'sort descending', defaultText: 'click to sort', }Specifies the screen reader only text that accompanies the sort buttons for sortable columns. It takes the form of an object containing the following keys:
asc
: (string) specifies the screen reader only text for sort buttons in the ascending state.desc
: (string) specifies the screen reader only text for sort buttons in the descending state.defaultText
: (string) specifies the screen reader only text for sort buttons that are not engaged.
It is only required if
tableSortable
is set totrue
.Default:
{ asc: 'sort ascending', desc: 'sort descending', defaultText: 'click to sort', }
rowHeaderColumnKey
string
Specifies the key for the column that should act as a row header. Rather than rendering as
<td>
elements, cells in this column will render as<th scope="row">
getCellProps
func
RequiredProps for the td element
render
func
RequiredFunction that renders the cell contents. Will be called with the string 'Cell'
column
shape
{cellClassName:} Requiredstring
,Table column
getHeaderProps
func
RequiredReturns props for the th element
isSorted
bool
DefaultfalseIndicates whether or not a column is sorted
render
func
RequiredRenders the header content. Passed the string 'Header'
isSortedDesc
bool
DefaultfalseIndicates whether the column is sorted in descending order
getSortByToggleProps
func
Default() => {}Gets props related to sorting that will be passed to th
canSort
bool
DefaultfalseIndicates whether a column is sortable
headerClassName
string
DefaultnullClass(es) to be applied to header cells
headerGroups
shape
{headers:shape
{getHeaderProps:}func
Required,[]
Required,getHeaderGroupProps:}func
Required,[]
Required
row
shape
{getRowProps:func
Required,cells:shape
{}[]
Required,id:string
Required,isSelected:bool
,isExpanded:} Requiredbool
,Row data that is received from
react-table
API.
className
string
Default''The class name for the CardGrid component
columnSizes
shape
{xs:number
,sm:number
,md:number
,lg:number
,xl:}number
,Default{ xs: 12, lg: 6, xl: 4, }An object containing the desired column size at each breakpoint, following a similar props API as
react-bootstrap/Col
CardComponent
func
RequiredYour card component must be individualized to your table. It will be called with props from the "row" of data it will display