Datatables
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
*
*
UMD autoinits are enabled
by default. This means that you don't need to initialize
the component manually. However if you are using MDBootstrap ES format then you should pass
the required components to the initMDB
method.
Video tutorial
Basic example - HTML markup
The Datatable component can render your data in three ways. In the first one, you simply
create a HTML markup for your table nested within a div tag with a datatable
class for styling and
data-mdb-datatable-init
that initialize JS interactions tat run under the hood. You can also
customize your table by adding data-mdb-attributes to the wrapper. Some of the more
advanced options for columns, described in the
Advanced Data Structure section can be also
used by setting data-mdb-attributes directly to a th tag (f.e.
<th data-mdb-sort="false">
).
Datatable collects information from HTML markup to create a data structure - the
<table>
element will be replaced in the DOM with a different node after
component initializes.
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:

Need even more robust tables? Try Data Den.
- Quick customization & hyper-focus on data management
- Easily integrate it with any project (not only MDB)
- Column Pinning, Drag&Drop Columns, Advanced Filtering & much more
For enterprise projects & users seeking advanced data controls. Tailor your data your way.
Basic data structure
The second 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
The last 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.
You can also use a mixed version, where columns are an array of object and each row is an array of strings.
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
The search field is not a part of the Datatable - place an input field on your page and use
.search()
method to filter entries.
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 listening to the
rowSelected.mdb.datatable
event.
|
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
option 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
.
Using fixed columns in a vertically scrollable table, requires setting an option
fixedHeader
to true
as well.
When using a HTML markup instead of a data structure you can still use this feature by setting
data-mdb-width
and data-mdb-fixed
attributes on your th tags.
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 an API using the
update
method. Additionally, setting a loading
option to
true
will disable all interactions and display a simple loader while awaiting
data.
The example below demonstrates loading data after the button is pressed.
Name | Phone | Username | Website | Address | Company |
---|
Loading results...
Rows per page:
Action buttons
With the Datatable it's possible to render custom content, such as action buttons and attach
listeners to their events. Keep in mind, that the component rerenders content when various
actions occur (f.e. sort, search) and event listeners need to be updated. To make it possible,
the components emits a custom event render.mdb.datatable
.
Name | Position | Office | Contact |
---|---|---|---|
Tiger Nixon | System Architect | Edinburgh | |
Sonya Frost | Software Engineer | Edinburgh | |
Tatyana Fitzpatrick | Regional Director | London |
Rows per page:
Cell formatting
Use cell formatting to color individual cells.
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 rowClicked
event.
Note: To prevent this action with other clickable elements within the row, call
stopPropagation()
method.
Note: This feature cannot be used simultaneously with edit
option.
Rows per page:
Datatables - API
Import
Importing components depends on how your application works. If you intend to use the MDBootstrap ES
format, you must
first import the component and then initialize it with the initMDB
method. If you are going to use the UMD
format,
just import the mdb-ui-kit
package.
Usage
Via data attributes
Using the Datatable component doesn't require any additional JavaScript code - simply add
data-mdb-datatable-init
attribute to
.datatable
and use other data attributes to set all options.
For ES
format, you must first import and call the initMDB
method.
Via JavaScript
Via jQuery
Note: By default, MDB does not include jQuery and you have to add it to the project on your own.
Options
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to
data-mdb-
, as in data-mdb-all-text=""
.
Name | Type | Default | Description |
---|---|---|---|
allText
|
String | 'All' |
Changes text for All in the pagination select |
bordered
|
Boolean | false |
Adds borders to a datatable |
borderless
|
Boolean | false |
Removes all borders from a datatable |
borderColor
|
String | null | null |
Changes a border color to one of main colors |
color |
String | null | null |
Adds a color class to a datatable (f.e 'bg-dark') |
defaultValue
|
String | '-' |
This string will be used as a placeholder if a row doesn't have a defined value for a column |
edit |
Boolean | false |
Enables edit mode |
entries
|
Number | String | 10 |
Number of visible entries (pagination) |
entriesOptions
|
Array | [10, 25, 50, 200] |
Options available to choose from in a pagination select (rows per page). Array with the available options may contain numbers and 'All' to display all entries on single page. |
fixedHeader
|
Boolean | false |
When it's set to true, the table's header will remain visible while scrolling |
forceSort
|
Boolean | false |
When it's set to true, the table's sort will toggle between two options: ascending and descending. The initial state will not be one of the options. |
fullPagination
|
Boolean | false |
Displays additional buttons for the first and last pages |
hover |
Boolean | false |
Changes the background color of a hovered row |
loading
|
Boolean | false |
Sets the loading mode - disables interactions and displays a loader |
loaderClass
|
String | 'bg-primary' |
The class name for a loader (loading mode) |
loadingMessage
|
String | 'Loading results...' |
A message displayed while loading data |
maxWidth
|
Number | String | null | null |
Sets a maximum width of a datatable - can be either a string ('10%') or a number of pixels. |
maxHeight
|
Number | String | null | null |
Sets a maximum height of a datatable - can be either a string ('10%') or a number of pixels. |
selectable
|
Boolean | false |
Enables selecting rows with checkboxes |
multi |
Boolean | false |
Allows selecting multiple rows (selectable mode) |
noFoundMessage
|
String | 'No matching results found' |
A message displayed when a table is empty |
pagination
|
Boolean | true |
Shows/hides the pagination panel |
sm |
Boolean | false |
Decreases a row's paddings |
striped
|
Boolean | false |
Slightly changes the background's color in every other row |
rowsText
|
String | 'Rows per page:' |
A text indicating a number of rows per page |
ofText
|
String | 'of' |
A message displayed as pagination description |
clickableRows
|
Boolean | false |
Makes rows clickable |
sortField
|
String | null | null |
Sorts given field on init. To use it via data attributes additionally data-mdb-field attribute needs to be added to column th element. e.g. <th data-mdb-field="age">Age</th>
|
sortOrder
|
String | 'asc' |
Defines an order in which initial sorting will sort. Use 'asc' for ascending order, and 'desc' for descending order (works only when data is injected with JS) |
Options (column)
Name | Type | Default | Description |
---|---|---|---|
label |
String | '' |
A displayed header of a column |
field |
String | '' |
A field's name - will be used as a key for values in rows |
fixed |
Boolean | String | false |
When set to true , makes a column stick on the left while scrolling.
Changing its value to right will do the same on the other side. For this
option to work, you need to define width as well.
|
width |
Number | null | null |
A column's width in pixels |
sort |
Boolean | true |
Enables/disables sorting for this column |
format(cell, value) |
Function | null | null |
Function runs for each cell, taking the DOM node & cell's value as its parameters |
Methods
Name | Description | Example |
---|---|---|
update |
Updates and rerenders datatable. |
myDatatable.update(data: Object, options: Object)
|
setActivePage |
Sets a specific page of entries. Page count starts from 0 . |
myDatatable.setActivePage(index)
|
search |
Filters rows so there are only those containing the searched phrase. |
myDatatable.search(phrase: String, column: String|Array (optional))
|
dispose
|
Removes the component's instance. |
myDatatable.dispose()
|
getInstance
|
Static method which allows you to get the datatable instance associated to a DOM element. |
Datatable.getInstance(datatableEl)
|
getOrCreateInstance
|
Static method which returns the datatable instance associated to a DOM element or create a new one in case it wasn't initialized. |
Datatable.getOrCreateInstance(datatableEl)
|
Events
Name | Description |
---|---|
update.mdb.datatable
|
This event is triggered in an editable mode when a user updates values. You can access the
updated data inside a listener's handler with
event.rows and event.columns fields.
|
rowSelected.mdb.datatable
|
This event is triggered when a user selects rows using checkboxes. You can access information about selected rows through the following properties of the emitted event:
selectedRows: Array , selectedIndexes: Array ,
allSelected: Boolean
|
render.mdb.datatable
|
This event is triggered after the component renders/updates rows. |
rowClicked.mdb.datatable
|
This event is triggered after clicking on a row. |