Datatables

Angular 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

Video tutorial


Basic example

Name Position Office Age Start date Salary
Tiger Nixon System Architect Edinburgh 61 2011/04/25 $320,800
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 Designert London 43 2012/12/18 $313,500
Tatyana Fitzpatrick Regional Director London 19 2010/03/17 $385,750
Michael Silva Marketing Designer London 66 2012/11/27 $198,500
Paul Byrd Chief Financial Officer (CFO) New York 64 2010/06/09 $725,000
Gloria Little Systems Administrator New York 59 2009/04/10 $237,500
Garrett Winters Accountant Tokyo 63 2011/07/25 $170,750
Quinn Flynn Support Lead Edinburgh 22 2013/03/03 $342,000
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



Scroll

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


Fixed header

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


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.


Action buttons

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


Clickable rows

Click on the row to preview the message.

Selecting the row with checkbox doesn't trigger rowClick 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.

Datatables - API


Import

Via data attributes


        import { MdbTableModule } from 'mdb-angular-ui-kit/table';
        …
        @NgModule ({
          ...
          imports: [MdbTableModule],
          ...
        })
      

Inputs

MdbTableDirective

Name Type Default Description
bordered Boolean false Adds borders to a datatable
borderless Boolean false Removes all borders from a datatable
dataSource T[] []] Changes table data source array
fixedHeader Boolean false When it's set to true, the table's header will remain visible while scrolling
filterFn (data: T, searchTerm: string) => boolean - Changes function used for data search
hover Boolean false Changes the background color of a hovered row
pagination MdbTablePaginationComponent - Changes attached table pagination component
selectable Boolean false Enables selecting rows with checkboxes
sort MdbTableSortDirective - Changes attached table sort directive
multi Boolean false Allows selecting multiple rows (selectable mode)
sm Boolean false Decreases a row's paddings
striped Boolean false Slightly changes the background's color in every other row
clickableRows Boolean false Makes rows clickable

MdbTableSortHeaderDirective

Name Type Default Description
mdbTableSortHeader string '' Changes name of the sort header

MdbTablePaginationComponent

Name Type Default Description
entries number 10 Changes number of displayed entries
entriesOptions Array [10, 25, 50, 200] Options available to choose from in a pagination select (rows per page)
prevButtonDisabled boolean false Whether previous button should be disabled
nextButtonDisabled boolean false Whether next button should be disabled
total number 0 Changes number of total pagination entries

Outputs

MdbTableSortDirective

Name Type Description
sortChange EventEmitter<MdbSortChange> Event fired on data sort change

MdbTablePaginationComponent

Name Type Description
paginationChange EventEmitter<MdbPaginationChange> Event fired on pagination change

            <div class="datatable mt-4">
              <table
                class="table datatable-table"
                mdbTable
                mdbTableSort
                #table="mdbTable"
                #sort="mdbTableSort"
                [dataSource]="dataSource"
                [pagination]="pagination"
                [sort]="sort"
                (sortChange)="onSortChange($event)"
              >
                <thead class="datatable-header">
                  <tr>
                    <th *ngFor="let header of headers" [mdbTableSortHeader]="header" scope="col">
                      {{ header | titlecase }}
                    </th>
                  </tr>
                </thead>
                <tbody class="datatable-body">
                  <tr *ngFor="let data of table.data" scope="row">
                    <td>
                      {{ data.name }}
                    </td>
                    <td>
                      {{ data.position }}
                    </td>
                    <td>
                      {{ data.office }}
                    </td>
                    <td>
                      {{ data.age }}
                    </td>
                    <td>
                      {{ data.startDate }}
                    </td>
                    <td>
                      {{ data.salary }}
                    </td>
                  </tr>
                </tbody>
              </table>
              <mdb-table-pagination #pagination (paginationChange)="onPaginationChange($event)"></mdb-table-pagination>
            </div>
          

            import { Component } from '@angular/core';
            import { MdbSortChange, MdbPaginationChange } from 'mdb-angular-ui-kit/table';

            export interface Person {
              name: string;
              position: string;
              office: string;
              age: number;
              startDate: string;
              salary: string;
            }

            @Component({ selector: 'app-datatable',
              templateUrl: './datatable.component.html',
              styleUrls: ['./datatable.component.scss'],
            })
            export class DatatableComponent {
              headers = ['Name', 'Position', 'Office', 'Age', 'Start Date', 'Salary'];

              dataSource: Person[] = [
                {
                  name: 'Tiger Nixon',
                  position: 'System Architect',
                  office: 'Edinburgh',
                  age: 61,
                  startDate: '2011/04/25',
                  salary: '$320,800',
                },
                {
                  name: 'Sonya Frost',
                  position: 'Software Engineer',
                  office: 'Edinburgh',
                  age: 23,
                  startDate: '2008/12/13',
                  salary: '$103,600',
                },
                {
                  name: 'Jena Gaines',
                  position: 'Office Manager',
                  office: 'London',
                  age: 30,
                  startDate: '2008/12/19',
                  salary: '$90,560',
                },
                {
                  name: 'Quinn Flynn',
                  position: 'Support Lead',
                  office: 'Edinburgh',
                  age: 22,
                  startDate: '2013/03/03',
                  salary: '$342,000',
                },
                {
                  name: 'Charde Marshall',
                  position: 'Regional Director',
                  office: 'San Francisco',
                  age: 36,
                  startDate: '2008/10/16',
                  salary: '$470,600',
                },
                {
                  name: 'Haley Kennedy',
                  position: 'Senior Marketing Designer',
                  office: 'London',
                  age: 43,
                  startDate: '2012/12/18',
                  salary: '$313,500',
                },
                {
                  name: 'Tatyana Fitzpatrick',
                  position: 'Regional Director',
                  office: 'London',
                  age: 19,
                  startDate: '2010/03/17',
                  salary: '$385,750',
                },
                {
                  name: 'Michael Silva',
                  position: 'Marketing Designer',
                  office: 'London',
                  age: 66,
                  startDate: '2012/11/27',
                  salary: '$198,500',
                },
                {
                  name: 'Paul Byrd',
                  position: 'Chief Financial Officer (CFO)',
                  office: 'New York',
                  age: 64,
                  startDate: '2010/06/09',
                  salary: '$725,000',
                },
                {
                  name: 'Gloria Little',
                  position: 'Systems Administrator',
                  office: 'New York',
                  age: 59,
                  startDate: '2009/04/10',
                  salary: '$237,500',
                },
                {
                  name: 'Garrett Winters',
                  position: 'Accountant',
                  office: 'Tokyo',
                  age: 63,
                  startDate: '2011/07/25',
                  salary: '$170,750',
                },
                {
                  name: 'Ashton Cox',
                  position: 'Junior Technical Author',
                  office: 'San Francisco',
                  age: 66,
                  startDate: '2009/01/12',
                  salary: '$86,000',
                },
                {
                  name: 'Cedric Kelly',
                  position: 'Senior Javascript Developer',
                  office: 'Edinburgh',
                  age: 22,
                  startDate: '2012/03/29',
                  salary: '$433,060',
                },
                {
                  name: 'Airi Satou',
                  position: 'Accountant',
                  office: 'Tokyo',
                  age: 33,
                  startDate: '2008/11/28',
                  salary: '$162,700',
                },
                {
                  name: 'Brielle Williamson',
                  position: 'Integration Specialist',
                  office: 'New York',
                  age: 61,
                  startDate: '2012/12/02',
                  salary: '$372,000',
                },
              ];

              constructor() {}

              onSortChange(event: MdbSortChange): void {
                console.log('sort change event', event);
              }

              onPaginationChange(event: MdbPaginationChange): void {
                console.log('pagination change event', event);
              }
            }