Data views
There 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.
Any Paragon component or export may be added to the code example.
The DataTable.Table component expects to receive a react-table instance from the DataTableContext.
- captionDefaultnull
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. IfcolumnSortableistrue, a sort button will be rendered in the column table heading. It is only required iftableSortableis set totrue.onSort(function; conditionally required) specifies what function is called when a sortable column is clicked. It is only required if the column'scolumnSortableis 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 ifhasFixedColumnWidthsis set totrue, the<td>elements'classattributes will be set to this value. This allows restricting columns to specific widths. See Bootstrap's grid documentation forcolclass names that can be used.
The order of objects in
columnsspecifies the order of the columns in the table. - columns
shape{key:stringRequired,label:string|elementRequired,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. IfcolumnSortableistrue, a sort button will be rendered in the column table heading. It is only required iftableSortableis set totrue.onSort(function; conditionally required) specifies what function is called when a sortable column is clicked. It is only required if the column'scolumnSortableis 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 ifhasFixedColumnWidthsis set totrue, the<td>elements'classattributes will be set to this value. This allows restricting columns to specific widths. See Bootstrap's grid documentation forcolclass names that can be used.
The order of objects in
columnsspecifies 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
boolDefaultfalseSpecifies whether the table is sortable. This setting supercedes column-level sortability, so if it is
false, no sortable components will be rendered. - hasFixedColumnWidths
boolDefaultfalseSpecifies whether the table's columns have fixed widths. Every element in
columnsmust define awidthif 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
tableSortableis set totrue. - defaultSortDirection
isRequiredIf(PropTypes.string, props => props.tableSortable)Specifies the direction the
defaultSortedColumnis sorted in by default; it will typically be either 'asc' or 'desc'. It is only required iftableSortableis 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
tableSortableis set totrue.Default:
{asc: 'sort ascending',desc: 'sort descending',defaultText: 'click to sort',} - rowHeaderColumnKey
stringSpecifies 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:funcRequired,cells:shape{}[]Required,id:stringRequired,isSelected:bool,isExpanded:} Requiredbool,Row data that is received from
react-tableAPI.
- getCellProps
funcRequiredProps for the td element
- render
funcRequiredFunction that renders the cell contents. Will be called with the string 'Cell'
- column
shape{cellClassName:} Requiredstring,Table column
- getHeaderProps
funcRequiredReturns props for the th element
- isSorted
boolDefaultfalseIndicates whether or not a column is sorted
- render
funcRequiredRenders the header content. Passed the string 'Header'
- isSortedDesc
boolDefaultfalseIndicates whether the column is sorted in descending order
- getSortByToggleProps
funcDefault() => {}Gets props related to sorting that will be passed to th
- canSort
boolDefaultfalseIndicates whether a column is sortable
- headerClassName
stringDefaultnullClass(es) to be applied to header cells
- headerGroups
shape{headers:shape{getHeaderProps:}funcRequired,[]Required,getHeaderGroupProps:}funcRequired,[]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.
Any Paragon component or export may be added to the code example.
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
stringThe 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
funcRequiredYour card component must be individualized to your table. It will be called with props from the "row" of data it will display
- selectionPlacement
enum'left' | 'right'Default'right'If the Cards are selectable this prop determines from which side of the Card to show selection component.
- SkeletonCardComponent
funcOverrides default skeleton card component for loading state in CardView
- skeletonCardCount
numberDefault8Customize the number of loading skeleton cards to display in CardView
const MiyazakiCard = ({ className, original }) => {const { title, director, release_date } = original;return (<Card className={className}><Card.ImageCap src="https://picsum.photos/360/200/" srcAlt="Card image" /><Card.Section title={title}><dl><dt>Director</dt><dd>{director}</dd><dt>Release Date</dt><dd>{release_date}</dd></dl></Card.Section></Card>);};
Theme Variables (SCSS)#
$data-table-background-color: $white !default;$data-table-border: 1px solid $gray-200 !default;$data-table-box-shadow: $box-shadow-sm !default;$data-table-padding-x: .75rem !default;$data-table-padding-y: .75rem !default;$data-table-padding-small: .5rem !default;$data-table-cell-padding: .5rem .75rem !default;$data-table-footer-position: center !default;$data-table-pagination-dropdown-max-height: 60vh !default;$data-table-pagination-dropdown-min-width: 6rem !default;$data-table-layout-sidebar-width: 12rem !default;
Props API#
- columns
shape{Header:func|nodeRequired,accessor:requiredWhenNot(PropTypes.string, 'Cell'),Cell:func|element,Filter:func,filter:string,filterChoices:}shape{name:string,number:number,value:}string,[],[]RequiredDefinition of table columns
- data
shape{}[]RequiredData to be displayed in the table
- isSelectable
boolDefaultfalsetable rows can be selected
- manualSelectColumn
shape{id:stringRequired,Header:func|nodeRequired,Cell:funcRequired,disableSortBy:}boolRequired,Alternate column for selecting rows. See react table useSort docs for more information
- isSortable
boolDefaultfalseTable columns can be sorted
- manualSortBy
boolDefaultfalseIndicates that sorting will be done via backend API. A fetchData function must be provided
- isPaginated
boolDefaultfalsePaginate the table
- manualPagination
boolDefaultfalseIndicates that pagination will be done manually. A fetchData function must be provided
- pageCount
requiredWhen(PropTypes.number, 'manualPagination') - isFilterable
boolDefaultfalseTable rows can be filtered, using a default filter in the default column values, or in the column definition
- manualFilters
boolDefaultfalseIndicates that filtering will be done via a backend API. A fetchData function must be provided
- defaultColumnValues
shape{Filter:}func|node,Default{}defaults that will be set on each column. Will be overridden by individual column values
- additionalColumns
shape{id:stringRequired,Header:string|node,Cell:}func|node,[]Default[]Actions or other additional non-data columns can be added here
- fetchData
funcDefaultnullFunction that will fetch table data. Called when page size, page index or filters change. Meant to be used with manual filters and pagination
- initialState
shape{pageSize:requiredWhen(PropTypes.number, 'isPaginated'),pageIndex:requiredWhen(PropTypes.number, 'isPaginated'),filters:requiredWhen(PropTypes.arrayOf(PropTypes.shape()), 'manualFilters'),sortBy:requiredWhen(PropTypes.arrayOf(PropTypes.shape()), 'manualSortBy'),selectedRowIds:shape{0:any,1:any,2:any,3:any,4:any,5:any,6:any,7:any,8:any,9:any,10:any,11:any,12:any,13:any,14:any,15:any,16:},any,selectedRowsOrdered:}number[],Default{}Initial state passed to react-table's documentation https://react-table.tanstack.com/docs/api/useTable
- initialTableOptions
shape{}Default{}Table options passed to react-table's useTable hook. Will override some options passed in to DataTable, such as: data, columns, defaultColumn, manualFilters, manualPagination, manualSortBy, and initialState
- itemCount
numberRequiredActions to be performed on the table. Called with the table instance. Not displayed if rows are selected.
- bulkActions
shape{buttonText:stringRequired,handleClick:funcRequired,className:string,variant:string,disabled:} |bool,func|element[]|func|elementDefault[]Actions to be performed on selected rows of the table. Called with the selected rows. Only displayed if rows are selected.
- tableActions
shape{buttonText:stringRequired,handleClick:funcRequired,className:string,variant:string,disabled:} |bool,func|element[]|func|elementDefault[]Function for rendering custom components, called with the table instance
- numBreakoutFilters
enum1 | 2 | 3 | 4Default1Number between one and four filters that can be shown on the top row.
- EmptyTableComponent
funcDefaultEmptyTableContentComponent to be displayed when the table is empty
- RowStatusComponent
funcDefaultRowStatusComponent to be displayed for row status, ie, 10 of 20 rows. Displayed by default in the TableControlBar
- SelectionStatusComponent
funcDefaultSelectionStatusComponent to be displayed for selection status. Displayed when there are selected rows and no active filters
- FilterStatusComponent
funcDefaultFilterStatusComponent to be displayed for filter status. Displayed when there are active filters.
- children
node[]|nodeDefaultnullIf children are not provided a table with control bar and footer will be rendered
- showFiltersInSidebar
boolDefaultfalseIf true filters will be shown on sidebar instead
- dataViewToggleOptions
shape{isDataViewToggleEnabled:bool,onDataViewToggle:func,defaultActiveStateValue:string,togglePlacement:}string,Default{ isDataViewToggleEnabled: false, onDataViewToggle: () => {}, defaultActiveStateValue: 'card', togglePlacement: 'left', }options for data view toggle
- disableElevation
boolDefaultfalseRemove the default box shadow on the component
- renderRowSubComponent
funcA function that will render contents of expanded row, accepts
rowas a prop. - isExpandable
boolDefaultfalseIndicates whether table supports expandable rows.
- isLoading
boolDefaultfalseIndicates whether the table should show loading states.
- onSelectedRowsChanged
funcCallback function called when row selections change.
- maxSelectedRows
numberIndicates the max of rows selectable in the table. Requires isSelectable prop
- onMaxSelectedRows
funcCallback after selected max rows. Requires isSelectable and maxSelectedRows props
- className
stringDefaultnullSpecifies class name to append to the base element
- captionDefaultnull
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. IfcolumnSortableistrue, a sort button will be rendered in the column table heading. It is only required iftableSortableis set totrue.onSort(function; conditionally required) specifies what function is called when a sortable column is clicked. It is only required if the column'scolumnSortableis 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 ifhasFixedColumnWidthsis set totrue, the<td>elements'classattributes will be set to this value. This allows restricting columns to specific widths. See Bootstrap's grid documentation forcolclass names that can be used.
The order of objects in
columnsspecifies the order of the columns in the table. - columns
shape{key:stringRequired,label:string|elementRequired,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. IfcolumnSortableistrue, a sort button will be rendered in the column table heading. It is only required iftableSortableis set totrue.onSort(function; conditionally required) specifies what function is called when a sortable column is clicked. It is only required if the column'scolumnSortableis 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 ifhasFixedColumnWidthsis set totrue, the<td>elements'classattributes will be set to this value. This allows restricting columns to specific widths. See Bootstrap's grid documentation forcolclass names that can be used.
The order of objects in
columnsspecifies 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
boolDefaultfalseSpecifies whether the table is sortable. This setting supercedes column-level sortability, so if it is
false, no sortable components will be rendered. - hasFixedColumnWidths
boolDefaultfalseSpecifies whether the table's columns have fixed widths. Every element in
columnsmust define awidthif 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
tableSortableis set totrue. - defaultSortDirection
isRequiredIf(PropTypes.string, props => props.tableSortable)Specifies the direction the
defaultSortedColumnis sorted in by default; it will typically be either 'asc' or 'desc'. It is only required iftableSortableis 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
tableSortableis set totrue.Default:
{ asc: 'sort ascending', desc: 'sort descending', defaultText: 'click to sort', } - rowHeaderColumnKey
stringSpecifies 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
funcRequiredProps for the td element
- render
funcRequiredFunction that renders the cell contents. Will be called with the string 'Cell'
- column
shape{cellClassName:} Requiredstring,Table column
- getHeaderProps
funcRequiredReturns props for the th element
- isSorted
boolDefaultfalseIndicates whether or not a column is sorted
- render
funcRequiredRenders the header content. Passed the string 'Header'
- isSortedDesc
boolDefaultfalseIndicates whether the column is sorted in descending order
- getSortByToggleProps
funcDefault() => {}Gets props related to sorting that will be passed to th
- canSort
boolDefaultfalseIndicates whether a column is sortable
- headerClassName
stringDefaultnullClass(es) to be applied to header cells
- headerGroups
shape{headers:shape{getHeaderProps:}funcRequired,[]Required,getHeaderGroupProps:}funcRequired,[]Required
- row
shape{getRowProps:funcRequired,cells:shape{}[]Required,id:stringRequired,isSelected:bool,isExpanded:} Requiredbool,Row data that is received from
react-tableAPI.
- className
stringThe 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
funcRequiredYour card component must be individualized to your table. It will be called with props from the "row" of data it will display
- selectionPlacement
enum'left' | 'right'Default'right'If the Cards are selectable this prop determines from which side of the Card to show selection component.
- SkeletonCardComponent
funcOverrides default skeleton card component for loading state in CardView
- skeletonCardCount
numberDefault8Customize the number of loading skeleton cards to display in CardView
Usage Insights#
CardView
| Project Name | Paragon Version | Instance Count | |
|---|---|---|---|
| frontend-app-admin-portal | 20.46.3 | 2 | |
| frontend-app-course-authoring | 20.46.2 | 2 | |
| frontend-app-enterprise-public-catalog | 20.46.3 | 2 | |
| frontend-app-learning | 20.46.0 | 1 |
DataTable
| Project Name | Paragon Version | Instance Count | |
|---|---|---|---|
| edx-ora2 | 20.9.2 | 1 | |
| frontend-app-admin-portal | 20.46.3 | 17 | |
| frontend-app-communications | 20.46.2 | 2 | |
| frontend-app-course-authoring | 20.46.2 | 3 | |
| frontend-app-ecommerce | 20.46.2 | 1 | |
| frontend-app-enterprise-public-catalog | 20.46.3 | 2 | |
| frontend-app-gradebook | 20.45.0 | 3 | |
| frontend-app-learner-record | 20.46.3 | 1 | |
| frontend-app-learning | 20.46.0 | 3 | |
| frontend-app-ora-grading | 20.46.3 | 2 | |
| frontend-app-publisher | 20.46.2 | 1 | |
| frontend-app-support-tools | 20.46.0 | 2 |
DataTableTable
| Project Name | Paragon Version | Instance Count | |
|---|---|---|---|
| edx-ora2 | 20.9.2 | 1 | |
| frontend-app-admin-portal | 20.46.3 | 6 | |
| frontend-app-course-authoring | 20.46.2 | 2 | |
| frontend-app-ecommerce | 20.46.2 | 1 | |
| frontend-app-enterprise-public-catalog | 20.46.3 | 1 | |
| frontend-app-gradebook | 20.45.0 | 1 | |
| frontend-app-learner-record | 20.46.3 | 1 | |
| frontend-app-learning | 20.46.0 | 2 | |
| frontend-app-ora-grading | 20.46.3 | 2 |
Table
| Project Name | Paragon Version | Instance Count | |
|---|---|---|---|
| edx-platform | 2.6.4 | 2 | |
| frontend-app-admin-portal | 20.46.3 | 1 | |
| studio-frontend | 3.4.8 | 1 |