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.

        
            
            import React from 'react';
            import { MDBDatatable } from 'mdb-react-ui-kit';
            
            export default function App() {

              const basicData = {
                columns: ['Name', 'Position', 'Office', 'Age', 'Start date', 'Salary'],
                rows: [
                  ['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'],
                  ['Jena Gaines', 'Office Manager', 'London', '30', '2008/12/19', '$90,560'],
                  ['Quinn Flynn', 'Support Lead', 'Edinburgh', '22', '2013/03/03', '$342,000'],
                  ['Charde Marshall', 'Regional Director', 'San Francisco', '36', '2008/10/16', '$470,600'],
                  ['Haley Kennedy', 'Senior Marketing Designer', 'London', '43', '2012/12/18', '$313,500'],
                ],
              };

              return (
                <MDBDatatable data={basicData} />
              );
            }
          
        
    

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.

        
            
            import React from 'react';
            import { MDBDatatable } from 'mdb-react-ui-kit';
            
            export default function App() {

              const advancedData = {
                columns: [
                  { label: 'Name', field: 'name', sort: true },
                  { label: 'Position', field: 'position', sort: false },
                  { label: 'Office', field: 'office', sort: false },
                  { label: 'Age', field: 'age', sort: false },
                  { label: 'Start date', field: 'date', sort: true },
                  { label: 'Salary', field: 'salary', sort: false },
                ],
                rows: [
                  {
                    name: 'Tiger Nixon',
                    position: 'System Architect',
                    office: 'Edinburgh',
                    age: 61,
                    date: '2011/04/25',
                    salary: '$320,800',
                  },
                  {
                    name: 'Garrett Winters',
                    position: 'Accountant',
                    office: 'Tokyo',
                    age: 63,
                    date: '2011/07/25',
                    salary: '$170,750',
                  },
                  {
                    name: 'Ashton Cox',
                    position: 'Junior Technical Author',
                    office: 'San Francisco',
                    age: 66,
                    date: '2009/01/12',
                    salary: '$86,000',
                  },
                  {
                    name: 'Cedric Kelly',
                    position: 'Senior Javascript Developer',
                    office: 'Edinburgh',
                    age: 22,
                    date: '2012/03/29',
                    salary: '$433,060',
                  },
                  { name: 'Airi Satou', position: 'Accountant', office: 'Tokyo', age: 33, date: '2008/11/28', salary: '$162,700' },
                  {
                    name: 'Brielle Williamson',
                    position: 'Integration Specialist',
                    office: 'New York',
                    age: 61,
                    date: '2012/12/02',
                    salary: '$372,000',
                  },
                  {
                    name: 'Herrod Chandler',
                    position: 'Sales Assistant',
                    office: 'San Francisco',
                    age: 59,
                    date: '2012/08/06',
                    salary: '$137,500',
                  },
                  {
                    name: 'Rhona Davidson',
                    position: 'Integration Specialist',
                    office: 'Tokyo',
                    age: 55,
                    date: '2010/10/14',
                    salary: '$327,900',
                  },
                  {
                    name: 'Colleen Hurst',
                    position: 'Javascript Developer',
                    office: 'San Francisco',
                    age: 39,
                    date: '2009/09/15',
                    salary: '$205,500',
                  },
                  {
                    name: 'Sonya Frost',
                    position: 'Software Engineer',
                    office: 'Edinburgh',
                    age: 23,
                    date: '2008/12/13',
                    salary: '$103,600',
                  },
                  {
                    name: 'Jena Gaines',
                    position: 'Office Manager',
                    office: 'London',
                    age: 30,
                    date: '2008/12/19',
                    salary: '$90,560',
                  },
                  {
                    name: 'Quinn Flynn',
                    position: 'Support Lead',
                    office: 'Edinburgh',
                    age: 22,
                    date: '2013/03/03',
                    salary: '$342,000',
                  },
                  {
                    name: 'Charde Marshall',
                    position: 'Regional Director',
                    office: 'San Francisco',
                    age: 36,
                    date: '2008/10/16',
                    salary: '$470,600',
                  },
                  {
                    name: 'Haley Kennedy',
                    position: 'Senior Marketing Designer',
                    office: 'London',
                    age: 43,
                    date: '2012/12/18',
                    salary: '$313,500',
                  },
                ],
              };

              return (
                <MDBDatatable data={advancedData} />
              );
            }
          
        
    



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.

        
            
            import React from 'react';
            import { MDBDatatable } from 'mdb-react-ui-kit';
            
            export default function App() {
              const basicData = {
                columns: ['Name', 'Position', 'Office', 'Age', 'Start date', 'Salary'],
                rows: [
                  ['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'],
                  ['Jena Gaines', 'Office Manager', 'London', '30', '2008/12/19', '$90,560'],
                  ['Quinn Flynn', 'Support Lead', 'Edinburgh', '22', '2013/03/03', '$342,000'],
                  ['Charde Marshall', 'Regional Director', 'San Francisco', '36', '2008/10/16', '$470,600'],
                  ['Haley Kennedy', 'Senior Marketing Designer', 'London', '43', '2012/12/18', '$313,500'],
                ],
              };

              return (
                <MDBDatatable
                  multi
                  selectable
                  data={basicData}
                />
              );
            }
          
        
    

Scroll

Setting maximum height/width will enable vertical/horizontal scrolling.

        
            
            import React from 'react';
            import { MDBDatatable } from 'mdb-react-ui-kit';
            
            export default function App() {

              const basicData = {
                columns: ['Name', 'Position', 'Office', 'Age', 'Start date', 'Salary'],
                rows: [
                  ['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'],
                  ['Jena Gaines', 'Office Manager', 'London', '30', '2008/12/19', '$90,560'],
                  ['Quinn Flynn', 'Support Lead', 'Edinburgh', '22', '2013/03/03', '$342,000'],
                  ['Charde Marshall', 'Regional Director', 'San Francisco', '36', '2008/10/16', '$470,600'],
                  ['Haley Kennedy', 'Senior Marketing Designer', 'London', '43', '2012/12/18', '$313,500'],
                ],
              };

              return (
                <MDBDatatable maxHeight='520px' maxWidth='520px' data={basicData} />
              );
            }
          
        
    

Fixed header

Use the fixedHeader property to ensure that a table's header is always visible while scrolling.

        
            
            import React, { useState } from 'react';
            import { MDBDatatable } from 'mdb-react-ui-kit';
            
            export default function App() {

              const basicData = {
                columns: ['Name', 'Position', 'Office', 'Age', 'Start date', 'Salary'],
                rows: [
                  ['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'],
                  ['Jena Gaines', 'Office Manager', 'London', '30', '2008/12/19', '$90,560'],
                  ['Quinn Flynn', 'Support Lead', 'Edinburgh', '22', '2013/03/03', '$342,000'],
                  ['Charde Marshall', 'Regional Director', 'San Francisco', '36', '2008/10/16', '$470,600'],
                  ['Haley Kennedy', 'Senior Marketing Designer', 'London', '43', '2012/12/18', '$313,500'],
                ],
              };

              return (
                <MDBDatatable fixedHeader maxHeight='460px' data={basicData} />
              );
            }
          
        
    

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.

        
            
            import React from 'react';
            import { MDBDatatable } from 'mdb-react-ui-kit';
            
            export default function App() {

              const fixedData = {
                columns: [
                  { label: 'Name', field: 'name', sort: true, width: 200, fixed: 'left' },
                  { label: 'Position', field: 'position', sort: false, width: 200 },
                  { label: 'Office', field: 'office', sort: false, width: 200, fixed: 'left', fixedValue: 200 },
                  { label: 'Age', field: 'age', sort: false, width: 200 },
                  { label: 'Start date', field: 'date', sort: true, width: 200 },
                  { label: 'Salary', field: 'salary', sort: false, width: 200, fixed: 'right' },
                ],
                rows: [
                  {
                    name: 'Tiger Nixon',
                    position: 'System Architect',
                    office: 'Edinburgh',
                    age: 61,
                    date: '2011/04/25',
                    salary: '$320,800',
                  },
                  {
                    name: 'Garrett Winters',
                    position: 'Accountant',
                    office: 'Tokyo',
                    age: 63,
                    date: '2011/07/25',
                    salary: '$170,750',
                  },
                  {
                    name: 'Ashton Cox',
                    position: 'Junior Technical Author',
                    office: 'San Francisco',
                    age: 66,
                    date: '2009/01/12',
                    salary: '$86,000',
                  },
                  {
                    name: 'Cedric Kelly',
                    position: 'Senior Javascript Developer',
                    office: 'Edinburgh',
                    age: 22,
                    date: '2012/03/29',
                    salary: '$433,060',
                  },
                  { name: 'Airi Satou', position: 'Accountant', office: 'Tokyo', age: 33, date: '2008/11/28', salary: '$162,700' },
                  {
                    name: 'Brielle Williamson',
                    position: 'Integration Specialist',
                    office: 'New York',
                    age: 61,
                    date: '2012/12/02',
                    salary: '$372,000',
                  },
                  {
                    name: 'Herrod Chandler',
                    position: 'Sales Assistant',
                    office: 'San Francisco',
                    age: 59,
                    date: '2012/08/06',
                    salary: '$137,500',
                  },
                  {
                    name: 'Rhona Davidson',
                    position: 'Integration Specialist',
                    office: 'Tokyo',
                    age: 55,
                    date: '2010/10/14',
                    salary: '$327,900',
                  },
                  {
                    name: 'Colleen Hurst',
                    position: 'Javascript Developer',
                    office: 'San Francisco',
                    age: 39,
                    date: '2009/09/15',
                    salary: '$205,500',
                  },
                  {
                    name: 'Sonya Frost',
                    position: 'Software Engineer',
                    office: 'Edinburgh',
                    age: 23,
                    date: '2008/12/13',
                    salary: '$103,600',
                  },
                  {
                    name: 'Jena Gaines',
                    position: 'Office Manager',
                    office: 'London',
                    age: 30,
                    date: '2008/12/19',
                    salary: '$90,560',
                  },
                  {
                    name: 'Quinn Flynn',
                    position: 'Support Lead',
                    office: 'Edinburgh',
                    age: 22,
                    date: '2013/03/03',
                    salary: '$342,000',
                  },
                  {
                    name: 'Charde Marshall',
                    position: 'Regional Director',
                    office: 'San Francisco',
                    age: 36,
                    date: '2008/10/16',
                    salary: '$470,600',
                  },
                  {
                    name: 'Haley Kennedy',
                    position: 'Senior Marketing Designer',
                    office: 'London',
                    age: 43,
                    date: '2012/12/18',
                    salary: '$313,500',
                  },
                ],
              };

              return (
                <MDBDatatable data={fixedData} />
              );
            }
          
        
    

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.

        
            
            import React, { useEffect, useState } from 'react';
            import { MDBDatatable, MDBBtn, MDBIcon } from 'mdb-react-ui-kit';
            
            export default function App() {

              const [asyncData, setAsyncData] = useState({
                columns: [
                  { label: 'Address', field: 'address' },
                  { label: 'Company', field: 'company' },
                  { label: 'Email', field: 'email' },
                  { label: 'Name', field: 'name' },
                  { label: 'Phone', field: 'phone' },
                  { label: 'Username', field: 'username' },
                  { label: 'Website', field: 'website' },
                ],
                rows: [],
              });

              const [loading, setLoading] = useState(false);

              useEffect(() => {
                if (loading) {
                  fetch('https://jsonplaceholder.typicode.com/users')
                    .then((response) => response.json())
                    .then((data) =>
                      setTimeout(() => {
                        setAsyncData({
                          columns: asyncData.columns,
                          rows: data.map((user: any) => ({
                            ...user,
                            address: `${user.address.city}, ${user.address.street}`,
                            company: user.company.name,
                          })),
                        });
                      }, 3000)
                    );
                }
              }, [loading, asyncData.columns]);
            
              useEffect(() => {
                if (asyncData.rows.length === 0) {
                  setLoading(true);
                } else {
                  setLoading(false);
                }
              }, [asyncData.rows]);

              return (
                <>
                  <MDBBtn className='mb-4' onClick={() => setAsyncData({ ...asyncData, rows: [] })}>
                    Reload data
                    <MDBIcon icon='sync' className='ms-2' />
                  </MDBBtn>
        
                  <MDBDatatable data={asyncData} isLoading={loading} />
                </>
              );
            }
          
        
    

Action buttons

With the Datatable it's possible to render custom content, such as action buttons and attach actions to their events.

        
            
            import React from 'react';
            import { MDBDatatable, MDBBtn, MDBIcon } from 'mdb-react-ui-kit';
            
            export default function App() {

              const actionData = {
                columns: [
                  { label: 'Name', field: 'name' },
                  { label: 'Position', field: 'position' },
                  { label: 'Office', field: 'office' },
                  { label: 'Contact', field: 'contact', sort: false },
                ],
                rows: [
                  {
                    name: 'Tiger Nixon',
                    position: 'System Architect',
                    office: 'Edinburgh',
                    phone: '+48000000000',
                    email: 'tiger.nixon@gmail.com',
                  },
                  {
                    name: 'Sonya Frost',
                    position: 'Software Engineer',
                    office: 'Edinburgh',
                    phone: '+53456123456',
                    email: 'sfrost@gmail.com',
                  },
                  {
                    name: 'Tatyana Fitzpatrick',
                    position: 'Regional Director',
                    office: 'London',
                    phone: '+42123432456',
                    email: 'tfitz@gmail.com',
                  },
                ].map((row) => {
                  return {
                    ...row,
                    contact: (
                      <>
                        <MDBBtn outline size='sm' floating className='call-btn' onClick={() => console.log(`call ${row.phone}`)}>
                          <MDBIcon icon='phone' />
                        </MDBBtn>
                        <MDBBtn
                          size='sm'
                          floating
                          className='message-btn ms-2'
                          onClick={() => console.log(`send a message to ${row.email}`)}
                        >
                          <MDBIcon icon='envelope' />
                        </MDBBtn>
                      </>
                    ),
                  };
                }),
              });

              return (
                <MDBDatatable hover data={actionData} />
              );
            }
          
        
    

Cell formatting

        
            
            import React from 'react';
            import { MDBDatatable } from 'mdb-react-ui-kit';
            
            export default function App() {

              const formatData = {
                columns: [
                  { label: 'Product', field: 'product' },
                  { label: 'Quantity', field: 'quantity' },
                  { label: 'Purchases', field: 'purchases' },
                ],
                rows: [
                  { product: 'Product 1', quantity: 10, purchases: 103 },
                  { product: 'Product 2', quantity: 45, purchases: 110 },
                  { product: 'Product 3', quantity: 76, purchases: 56 },
                  { product: 'Product 4', quantity: 89, purchases: 230 },
                  { product: 'Product 5', quantity: 104, purchases: 240 },
                  { product: 'Product 6', quantity: 97, purchases: 187 },
                  { product: 'Product 7', quantity: 167, purchases: 130 },
                  { product: 'Product 8', quantity: 50, purchases: 199 },
                  { product: 'Product 9', quantity: 4, purchases: 206 },
                  { product: 'Product 10', quantity: 120, purchases: 88 },
                  { product: 'Product 11', quantity: 22, purchases: 100 },
                ],
              };

              return (
                <MDBDatatable
                  data={formatData}
                  sortOrder='desc'
                  sortField='Purchases'
                  format={(field, value) => {
                    if (field === 'purchases') {
                      const colors = ['#E3F2FD', '#BBDEFB', '#90CAF9', '#64B5F6', '#42A5F5'];
    
                      const maxValue = Math.max(...formatData.rows.map((row) => row.purchases));
                      const minValue = Math.min(...formatData.rows.map((row) => row.purchases));
    
                      const step = (maxValue - minValue) / (colors.length - 1);
    
                      const colorIndex = Math.floor((value - minValue) / step);
    
                      return { backgroundColor: colors[colorIndex], fontWeight: 400 };
                    }
                  }}
                />
              );
            }
          
        
    

Clickable rows

Click on the row to preview the message.

Selecting the row with checkbox doesn't trigger rowClick event.

        
            
            import React, { useState } from 'react';
            import { 
              MDBDatatable, 
              MDBIcon,
              MDBModal,
              MDBModalBody,
              MDBModalDialog,
              MDBModalContent,
              MDBModalFooter,
              MDBModalHeader,
              MDBModalTitle,
              MDBBtn,
            } from 'mdb-react-ui-kit';
            
            export default function App() {

              const [basicModal, setBasicModal] = useState(false);
              const [selectedRowsAdvanced, setSelectedRowsAdvanced] = useState([]);
              const [modalState, setModalState] = useState({ from: '', message: '' });

              const clicakbleData = {
                columns: [
                  { label: 'Actions', field: 'actions', sort: false },
                  { label: 'From', field: 'from' },
                  { label: 'Title', field: 'title' },
                  { label: 'Message', field: 'preview', sort: false },
                  { label: 'Date', field: 'date' },
                ],
                rows: [
                  {
                    from: 'admin@mdbootstrap.com',
                    title: 'MDBootstrap spring sale',
                    message:
                      'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sed metus ultricies, sollicitudin est nec, blandit turpis. Fusce venenatis nisi volutpat, pharetra elit eu, ullamcorper metus. Vestibulum dapibus laoreet aliquam. Maecenas sed magna ut libero consequat elementum. Maecenas euismod pellentesque pulvinar. Morbi sit amet turpis eget dolor rutrum eleifend. Sed bibendum diam nec diam posuere pulvinar. Cras ac bibendum arcu.',
                    date: '11/12/2019',
                  },
                  {
                    from: 'user@mdbootstrap.com',
                    title: 'How to purchase MDB5 package?',
                    message:
                      'Quisque tempor ligula eu lobortis scelerisque. Mauris tristique mi a erat egestas, quis dictum nibh iaculis. Sed gravida sodales egestas. In tempus mollis libero sit amet lacinia. Duis non augue sed leo imperdiet efficitur faucibus vitae elit. Mauris eu cursus ligula. Praesent posuere efficitur cursus.',
                    date: '10/12/2019',
                  },
                  {
                    from: 'user@mdbootstrap.com',
                    title: 'Licence renewal',
                    message:
                      'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sed metus ultricies, sollicitudin est nec, blandit turpis. Fusce venenatis nisi volutpat, pharetra elit eu, ullamcorper metus. Vestibulum dapibus laoreet aliquam. Maecenas sed magna ut libero consequat elementum. Maecenas euismod pellentesque pulvinar. Morbi sit amet turpis eget dolor rutrum eleifend. Sed bibendum diam nec diam posuere pulvinar. Cras ac bibendum arcu.',
                    date: '09/12/2019',
                  },
                  {
                    from: 'admin@mdbootstrap.com',
                    title: 'Black friday offer',
                    message:
                      'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sed metus ultricies, sollicitudin est nec, blandit turpis. Fusce venenatis nisi volutpat, pharetra elit eu, ullamcorper metus. Vestibulum dapibus laoreet aliquam. Maecenas sed magna ut libero consequat elementum. Maecenas euismod pellentesque pulvinar. Morbi sit amet turpis eget dolor rutrum eleifend. Sed bibendum diam nec diam posuere pulvinar. Cras ac bibendum arcu.',
                    date: '08/12/2019',
                  },
                ].map((email, i) => {
                  const getPreview = (message: string, length: number) => {
                    if (message.length <= length) return message;
            
                    return `${message.slice(0, length)}...`;
                  };
            
                  return {
                    ...email,
                    preview: getPreview(email.message, 20),
                    actions: (
                      <>
                        <a
                          role='button'
                          onClick={() => console.log(`star message: ${i}`, email)}
                          className='star-email-button text-warning'
                        >
                          <MDBIcon far icon='star' className='datatable-disable-onclick' />
                        </a>
                        <a
                          role='button'
                          onClick={() => console.log(`delete message: ${i}`, email)}
                          className='delete-email-button text-muted ms-2'
                        >
                          <MDBIcon icon='trash-alt' className='datatable-disable-onclick' />
                        </a>
                      </>
                    ),
                  };
                }),
              };

              return (
                <>
                  <MDBDatatable
                    selectable
                    data={clicakbleData}
                    onRowClick={(row) => {
                      const rowElement = row as { from: string; message: string };
                      const { from, message } = rowElement;
      
                      setBasicModal(true);
                      setModalState({ from, message });
                    }}
                  />

                  <MDBModal show={basicModal} getOpenState={(e: any) => setBasicModal(e)} tabIndex='-1'>
                    <MDBModalDialog>
                      <MDBModalContent>
                        <MDBModalHeader>
                          <MDBModalTitle>MDBootstrap spring sale</MDBModalTitle>
                          <MDBBtn className='btn-close' color='none' onClick={() => setBasicModal(false)}></MDBBtn>
                        </MDBModalHeader>
                        <MDBModalBody>
                          <h6 className='mb-4'>
                            From: <strong>{modalState.from}</strong>
                          </h6>
                          <p>{modalState.message}</p>
                        </MDBModalBody>
        
                        <MDBModalFooter>
                          <MDBBtn outline>
                            Reply
                            <MDBIcon icon='paper-plane' className='ms-2' />
                          </MDBBtn>
                          <MDBBtn outline>
                            Forward
                            <MDBIcon icon='arrow-right' className='ms-2' />
                          </MDBBtn>
                        </MDBModalFooter>
                      </MDBModalContent>
                    </MDBModalDialog>
                  </MDBModal>
                </>
              );
            }
          
        
    

Datatables - API


Import

        
            
            import { MDBDatatable } from 'mdb-react-ui-kit';
          
        
    

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...' />
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

        
                  
              type DataType = {
                columns: ColumnsType;
                rows: RowsType;
              };
            
        
    

ColumnsType

        
                  
            type AdvancedHeader = {
              label: string;
              field: keyof AdvancedRecord;
              sort?: boolean;
              width?: number;
              fixed?: string;
              fixedValue?: number;
            };
              
            type ColumnsType = string[][] | AdvancedHeader[]; 
            
        
    

RowsType

        
                  
              type AdvancedRecord = Record<string, unknown>;
    
              type RowsType = unknown[][] | AdvancedRecord[];
            
        
    

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.