Table
Tables display sets of data. They can be fully customized.
Tables display information in a way that's easy to scan, so that users can look for patterns and insights. They can be embedded in primary content, such as cards. They can include:
- A corresponding visualization
- Navigation
- Tools to query and manipulate data
Data table
The Table
component has a close mapping to the native <table>
elements.
This constraint makes building rich data tables challenging.
The DataGrid
component is designed for use-cases that are focused on handling large amounts of tabular data.
While it comes with a more rigid structure, in exchange, you gain more powerful features.
Sorting & selecting
This example demonstrates the use of Checkbox
and clickable rows for selection, with a custom Toolbar
. It uses the TableSortLabel
component to help style column headings.
The Table has been given a fixed width to demonstrate horizontal scrolling. In order to prevent the pagination controls from scrolling, the TablePagination component is used outside of the Table. (The 'Custom Table Pagination Action' example below shows the pagination within the TableFooter.)
Customization
Here is an example of customizing the component. You can learn more about this in the overrides documentation page.
Custom pagination options
It's possible to customize the options shown in the "Rows per page" select using the rowsPerPageOptions
prop.
You should either provide an array of:
numbers, each number will be used for the option's label and value.
<TablePagination rowsPerPageOptions={[10, 50]} />
objects, the
value
andlabel
keys will be used respectively for the value and label of the option (useful for language strings such as 'All').<TablePagination rowsPerPageOptions={[10, 50, { value: -1, label: 'All' }]} />
Custom pagination actions
The ActionsComponent
prop of the TablePagination
component allows the implementation of custom actions.
Sticky header
Here is an example of a table with scrollable rows and fixed column headers.
It leverages the stickyHeader
prop.
(⚠️ no IE 11 support)
Column grouping
You can group column headers by rendering multiple table rows inside a table head:
<TableHead>
<TableRow />
<TableRow />
</TableHead>
Collapsible table
An example of a table with expandable rows, revealing more information.
It utilizes the Collapse
component.
Virtualized table
In the following example, we demonstrate how to use react-virtualized with the Table
component.
It renders 200 rows and can easily handle more.
Virtualization helps with performance issues.
Unstyled
If you would like to use an unstyled Table, you can use the primitive elements and enhance the table with the unstyled pagination as shown in the demo below.
Accessibility
(WAI tutorial: https://www.w3.org/WAI/tutorials/tables/)
Caption
A caption functions like a heading for a table. Most screen readers announce the content of captions. Captions help users to find a table and understand what it's about and decide if they want to read it.