Datatables
React Bootstrap 5 Datatables
The Datatable is a component which mix tables with advanced options like searching, sorting and pagination.
Note: Read the API tab to find all available options and advanced customization
Basic data structure
This option is a very basic data structure, where columns are represented by an array of strings and so is each row. The table will match each string in a row to a corresponding index in a columns array. This data structure, as it's based on indexes, not key-value pairs, can be easily used for displaying data from the CSV format.
Name | Position | Office | Age | Start date | Salary |
---|---|---|---|---|---|
Tiger Nixon | System Architect | Edinburgh | 61 | 2011/04/25 | $320,800 |
Garrett Winters | Accountant | Tokyo | 63 | 2011/07/25 | $170,750 |
Ashton Cox | Junior Technical Author | San Francisco | 66 | 2009/01/12 | $86,000 |
Cedric Kelly | Senior Javascript Developer | Edinburgh | 22 | 2012/03/29 | $433,060 |
Airi Satou | Accountant | Tokyo | 33 | 2008/11/28 | $162,700 |
Brielle Williamson | Integration Specialist | New York | 61 | 2012/12/02 | $372,000 |
Herrod Chandler | Sales Assistant | San Francisco | 59 | 2012/08/06 | $137,500 |
Rhona Davidson | Integration Specialist | Tokyo | 55 | 2010/10/14 | $327,900 |
Colleen Hurst | Javascript Developer | San Francisco | 39 | 2009/09/15 | $205,500 |
Sonya Frost | Software Engineer | Edinburgh | 23 | 2008/12/13 | $103,600 |
Rows per page:
Advanced data structure
Second and most advanced data structure allows customizing each column (sort, width, fixed, field) and matches values from each row to a column in which the `field` equals to a given key value. This data format can be easily used to display JSON data.
Name | Position | Office | Age | Start date | Salary |
---|---|---|---|---|---|
Tiger Nixon | System Architect | Edinburgh | 61 | 2011/04/25 | $320,800 |
Garrett Winters | Accountant | Tokyo | 63 | 2011/07/25 | $170,750 |
Ashton Cox | Junior Technical Author | San Francisco | 66 | 2009/01/12 | $86,000 |
Cedric Kelly | Senior Javascript Developer | Edinburgh | 22 | 2012/03/29 | $433,060 |
Airi Satou | Accountant | Tokyo | 33 | 2008/11/28 | $162,700 |
Brielle Williamson | Integration Specialist | New York | 61 | 2012/12/02 | $372,000 |
Herrod Chandler | Sales Assistant | San Francisco | 59 | 2012/08/06 | $137,500 |
Rhona Davidson | Integration Specialist | Tokyo | 55 | 2010/10/14 | $327,900 |
Colleen Hurst | Javascript Developer | San Francisco | 39 | 2009/09/15 | $205,500 |
Sonya Frost | Software Engineer | Edinburgh | 23 | 2008/12/13 | $103,600 |
Rows per page:
Search
Use search
proprty to add search field to the datatable.
Name | Position | Office | Age | Start date | Salary |
---|---|---|---|---|---|
Tiger Nixon | System Architect | Edinburgh | 61 | 2011/04/25 | $320,800 |
Garrett Winters | Accountant | Tokyo | 63 | 2011/07/25 | $170,750 |
Ashton Cox | Junior Technical Author | San Francisco | 66 | 2009/01/12 | $86,000 |
Cedric Kelly | Senior Javascript Developer | Edinburgh | 22 | 2012/03/29 | $433,060 |
Airi Satou | Accountant | Tokyo | 33 | 2008/11/28 | $162,700 |
Brielle Williamson | Integration Specialist | New York | 61 | 2012/12/02 | $372,000 |
Herrod Chandler | Sales Assistant | San Francisco | 59 | 2012/08/06 | $137,500 |
Rhona Davidson | Integration Specialist | Tokyo | 55 | 2010/10/14 | $327,900 |
Colleen Hurst | Javascript Developer | San Francisco | 39 | 2009/09/15 | $205,500 |
Sonya Frost | Software Engineer | Edinburgh | 23 | 2008/12/13 | $103,600 |
Rows per page:
Advanced search
When using the searching method, you can specify which columns it should take under consideration - pass as a second argument a field (or array of fields). By default, searching will apply to all columns.
Name | Position | Office | Age | Start date | Salary |
---|---|---|---|---|---|
Tiger Nixon | System Architect | Edinburgh | 61 | 2011/04/25 | $320,800 |
Garrett Winters | Accountant | Tokyo | 63 | 2011/07/25 | $170,750 |
Ashton Cox | Junior Technical Author | San Francisco | 66 | 2009/01/12 | $86,000 |
Cedric Kelly | Senior Javascript Developer | Edinburgh | 22 | 2012/03/29 | $433,060 |
Airi Satou | Accountant | Tokyo | 33 | 2008/11/28 | $162,700 |
Brielle Williamson | Integration Specialist | New York | 61 | 2012/12/02 | $372,000 |
Herrod Chandler | Sales Assistant | San Francisco | 59 | 2012/08/06 | $137,500 |
Rhona Davidson | Integration Specialist | Tokyo | 55 | 2010/10/14 | $327,900 |
Colleen Hurst | Javascript Developer | San Francisco | 39 | 2009/09/15 | $205,500 |
Sonya Frost | Software Engineer | Edinburgh | 23 | 2008/12/13 | $103,600 |
Rows per page:
Selectable rows
When the selectable option is set to true
, user can interact with your table by
selecting rows - you can get the selected rows by passing state through properties.
|
Name | Position | Office | Age | Start date | Salary |
---|---|---|---|---|---|---|
|
Tiger Nixon | System Architect | Edinburgh | 61 | 2011/04/25 | $320,800 |
|
Garrett Winters | Accountant | Tokyo | 63 | 2011/07/25 | $170,750 |
|
Ashton Cox | Junior Technical Author | San Francisco | 66 | 2009/01/12 | $86,000 |
|
Cedric Kelly | Senior Javascript Developer | Edinburgh | 22 | 2012/03/29 | $433,060 |
|
Airi Satou | Accountant | Tokyo | 33 | 2008/11/28 | $162,700 |
|
Brielle Williamson | Integration Specialist | New York | 61 | 2012/12/02 | $372,000 |
|
Herrod Chandler | Sales Assistant | San Francisco | 59 | 2012/08/06 | $137,500 |
|
Rhona Davidson | Integration Specialist | Tokyo | 55 | 2010/10/14 | $327,900 |
|
Colleen Hurst | Javascript Developer | San Francisco | 39 | 2009/09/15 | $205,500 |
|
Sonya Frost | Software Engineer | Edinburgh | 23 | 2008/12/13 | $103,600 |
Rows per page:
Scroll
Setting maximum height/width will enable vertical/horizontal scrolling.
Name | Position | Office | Age | Start date | Salary |
---|---|---|---|---|---|
Tiger Nixon | System Architect | Edinburgh | 61 | 2011/04/25 | $320,800 |
Garrett Winters | Accountant | Tokyo | 63 | 2011/07/25 | $170,750 |
Ashton Cox | Junior Technical Author | San Francisco | 66 | 2009/01/12 | $86,000 |
Cedric Kelly | Senior Javascript Developer | Edinburgh | 22 | 2012/03/29 | $433,060 |
Airi Satou | Accountant | Tokyo | 33 | 2008/11/28 | $162,700 |
Brielle Williamson | Integration Specialist | New York | 61 | 2012/12/02 | $372,000 |
Herrod Chandler | Sales Assistant | San Francisco | 59 | 2012/08/06 | $137,500 |
Rhona Davidson | Integration Specialist | Tokyo | 55 | 2010/10/14 | $327,900 |
Colleen Hurst | Javascript Developer | San Francisco | 39 | 2009/09/15 | $205,500 |
Sonya Frost | Software Engineer | Edinburgh | 23 | 2008/12/13 | $103,600 |
Rows per page:
Fixed header
Use the fixedHeader
property to ensure that a table's header is always visible
while scrolling.
Name | Position | Office | Age | Start date | Salary |
---|---|---|---|---|---|
Tiger Nixon | System Architect | Edinburgh | 61 | 2011/04/25 | $320,800 |
Garrett Winters | Accountant | Tokyo | 63 | 2011/07/25 | $170,750 |
Ashton Cox | Junior Technical Author | San Francisco | 66 | 2009/01/12 | $86,000 |
Cedric Kelly | Senior Javascript Developer | Edinburgh | 22 | 2012/03/29 | $433,060 |
Airi Satou | Accountant | Tokyo | 33 | 2008/11/28 | $162,700 |
Brielle Williamson | Integration Specialist | New York | 61 | 2012/12/02 | $372,000 |
Herrod Chandler | Sales Assistant | San Francisco | 59 | 2012/08/06 | $137,500 |
Rhona Davidson | Integration Specialist | Tokyo | 55 | 2010/10/14 | $327,900 |
Colleen Hurst | Javascript Developer | San Francisco | 39 | 2009/09/15 | $205,500 |
Sonya Frost | Software Engineer | Edinburgh | 23 | 2008/12/13 | $103,600 |
Rows per page:
Fixed columns
Making a column sticky requires setting two options - width and fixed. A first option is a
number of pixels, while the other one can be either a
true
( in which case the column will stick on the left) or a string
right
.
Name | Position | Office | Age | Start date | Salary |
---|---|---|---|---|---|
Tiger Nixon | System Architect | Edinburgh | 61 | 2011/04/25 | $320,800 |
Garrett Winters | Accountant | Tokyo | 63 | 2011/07/25 | $170,750 |
Ashton Cox | Junior Technical Author | San Francisco | 66 | 2009/01/12 | $86,000 |
Cedric Kelly | Senior Javascript Developer | Edinburgh | 22 | 2012/03/29 | $433,060 |
Airi Satou | Accountant | Tokyo | 33 | 2008/11/28 | $162,700 |
Brielle Williamson | Integration Specialist | New York | 61 | 2012/12/02 | $372,000 |
Herrod Chandler | Sales Assistant | San Francisco | 59 | 2012/08/06 | $137,500 |
Rhona Davidson | Integration Specialist | Tokyo | 55 | 2010/10/14 | $327,900 |
Colleen Hurst | Javascript Developer | San Francisco | 39 | 2009/09/15 | $205,500 |
Sonya Frost | Software Engineer | Edinburgh | 23 | 2008/12/13 | $103,600 |
Rows per page:
Async data
Loading content asynchronously is an important part of working with data tables - with MDB
Datatable you can easily display content after fetching it from API. Additionally, setting
a loading
property totrue
will disable all interactions and display
a simple loader while awaiting data.
Address | Company | Name | Phone | Username | Website |
---|
Loading results...
Rows per page:
Action buttons
With the Datatable it's possible to render custom content, such as action buttons and attach actions to their events.
Name | Position | Office | Contact |
---|---|---|---|
Tiger Nixon | System Architect | Edinburgh | |
Sonya Frost | Software Engineer | Edinburgh | |
Tatyana Fitzpatrick | Regional Director | London |
Rows per page:
Cell formatting
Product | Quantity | Purchases |
---|---|---|
Product 5 | 104 | 240 |
Product 4 | 89 | 230 |
Product 9 | 4 | 206 |
Product 8 | 50 | 199 |
Product 6 | 97 | 187 |
Product 7 | 167 | 130 |
Product 2 | 45 | 110 |
Product 1 | 10 | 103 |
Product 11 | 22 | 100 |
Product 10 | 120 | 88 |
Rows per page:
Clickable rows
Click on the row to preview the message.
Selecting the row with checkbox doesn't trigger rowClick
event.
Rows per page:
Datatables - API
Import
Properties
MDBDatatable
Name | Type | Default | Description | Example |
---|---|---|---|---|
allText
|
string | 'All' |
Changes text for All in the pagination select. |
<MDBDatatable allText='test' />
|
bordered
|
boolean | false |
Adds borders to a datatable. |
<MDBDatatable bordered />
|
borderless
|
boolean | false |
Removes all borders from a datatable. |
<MDBDatatable borderless />
|
borderColor
|
string | - |
Changes a border color to one of main colors. |
<MDBDatatable borderColor='red' />
|
color |
string | - |
Adds a color class to a datatable (f.e 'bg-dark') |
<MDBDatatable color='primary' />
|
data |
DataType | - |
Data passed to the Datatable. |
<MDBDatatable data={data} />
|
dark |
boolean | false |
Changes a font color to white. |
<MDBDatatable dark />
|
editable
|
boolean | false |
Enable the edit mode. |
<MDBDatatable editable />
|
entries
|
number | 10 |
Number of visible entries (pagination). |
<MDBDatatable entries={25} />
|
entriesOptions
|
number[] | [10, 25, 50, 200] |
Options available to choose from in a pagination select (rows per page). |
<MDBDatatable entriesOptions=[10, 20, 60] />
|
fixedHeader
|
boolean | false |
When it's set to true, the table's header will remain visible while scrolling. |
<MDBDatatable fixedHeader />
|
fullPagination
|
boolean | false |
Displays additional buttons for the first and last pages. |
<MDBDatatable fullPagination />
|
hover |
boolean | false |
Changes the background color of a hovered row. |
<MDBDatatable hover />
|
isLoading
|
boolean | false |
Set the loading mode. |
<MDBDatatable isLoading />
|
loaderClass
|
string | 'bg-primary' |
The class name for a loader (loading mode). |
<MDBDatatable loaderClass='bg-warning' />
|
loadingMessage
|
ReactNode | 'Loading results...' |
A message displayed while loading data. |
<MDBDatatable loaderClass='Loading...' />
|
maxWidth
|
string | - |
Sets a maximum width of a datatable - can be either a string ('10%') or a number of pixels. |
<MDBDatatable maxWidth='560px' />
|
maxHeight
|
string | - |
Sets a maximum height of a datatable - can be either a string ('10%') or a number of pixels. |
<MDBDatatable maxHeight='560px' />
|
multi |
boolean | false |
Allows selecting multiple rows (selectable mode). |
<MDBDatatable selectable multi />
|
noFoundMessage
|
ReactNode | 'No matching results found' |
A message displayed when a table is empty. |
<MDBDatatable noFoundMessage='Not found...' />
|
ofText
|
ReactNode | 'of' |
A message displayed as pagination description |
<MDBDatatable ofText='/' />
|
pagination
|
boolean | true |
Shows/hides the pagination panel. |
<MDBDatatable pagination={false} />
|
rowsText
|
string | 'Rows per page': |
A text indicating a number of rows per page. |
<MDBDatatable rowsText='Rows:' />
|
search
|
boolean | false |
Enable search in the table. |
<MDBDatatable search />
|
selectable
|
boolean | false |
Enable selecting rows with checkboxes. |
<MDBDatatable selectable />
|
sm |
boolean | false |
Decreases a row's paddings. |
<MDBDatatable sm />
|
striped
|
boolean | false |
Slightly changes the background's color in every other row. |
<MDBDatatable striped />
|
sortField
|
string | '' |
Allows default sorting of the table column |
<MDBDatatable sortField='ColumnName' />
|
sortOrder
|
string | 'asc' |
Defines the default sorting direction |
<MDBDatatable sortField='ColumnName' sortOrder='desc' />
|
searchInputProps
|
Record<string, unknown> | - |
Props for the search input |
<MDBDatatable searchInputProps={{ className='test' }} />
|
Properties
DataType
ColumnsType
RowsType
Methods
Name | Type | Description |
---|---|---|
advancedSearch
|
(value: string) => { phrase: string; columns: string | string[] } | Define advancedSearch for MDBDatatable |
format
|
(field: string | number | symbol, value: number) => CSSProperties | undefined | Define format function for MDBDatatable |
Events
Name | Type | Description |
---|---|---|
onRowClick
|
(row: RecordsType) => void | Event emitted after clicking on a row. |
onSelectRow
|
(selectedRows: RowsType, selectedIndexes: number[], allSelected: boolean) => void | This event fires when a user select rows with checkboxes. |