Angular Bootstrap table pagination

Divide long tables into pages with table pagination feature. Display your data clearly by using multiple table parts styled with Material Design. Check out examples and tutorial.


Basic example MDB Pro component Live Example

# First Name Last Name Username Username Username Username
1 Mark Otto @mdo Mark Otto @mdo
2 Jacob Thornton @fat Jacob Thornton @fat
3 Larry the Bird @twitter Larry the Bird @twitter
4 Paul Topolski @P_Topolski Paul Topolski @P_Topolski
5 Larry the Bird @twitter Larry the Bird @twitter

Table with pagination

# First Name Last Name Username
{{data.id}} {{data.firstName}} {{data.lastName}} {{data.username}}

import { Component, OnInit, ViewChildren, QueryList, ElementRef } from '@angular/core'; @Component({ selector: 'table-pagination', templateUrl: './table-pagination.component.html', styleUrls: ['./table-pagination.component.scss'], }) export class TablePaginationComponent implements OnInit { @ViewChildren('pages') pages: QueryList; itemsPerPage = 3; numberOfVisiblePaginators = 10; numberOfPaginators: number; paginators: Array = []; activePage = 1; firstVisibleIndex = 1; lastVisibleIndex: number = this.itemsPerPage; firstVisiblePaginator = 0; lastVisiblePaginator = this.numberOfVisiblePaginators; constructor(private el: ElementRef) {} tableData = [ { id: 1, firstName: 'Mark', lastName: 'Otto', username: '@mdo' }, { id: 2, firstName: 'John', lastName: 'Doe', username: '@john' }, { id: 3, firstName: 'Lessie', lastName: 'Moe', username: '@lessie' }, { id: 4, firstName: 'Otton', lastName: 'Otto', username: '@otton' }, { id: 5, firstName: 'Krauze', lastName: 'John', username: '@krauze' }, { id: 6, firstName: 'Lex', lastName: 'Lucky', username: '@lex' }, { id: 7, firstName: 'Allie', lastName: 'Bill', username: '@allie' }, { id: 8, firstName: 'Anna', lastName: 'Frost', username: '@anna' }, { id: 9, firstName: 'Bob', lastName: 'One', username: '@bob' }, { id: 10, firstName: 'Carl', lastName: 'Johnson', username: '@cj' }, { id: 11, firstName: 'Mia', lastName: 'Marx', username: '@mia' }, { id: 12, firstName: 'Cia', lastName: 'Fbi', username: '@cia' }, { id: 13, firstName: 'John', lastName: 'Doe', username: '@johny' }, { id: 14, firstName: 'Mark', lastName: 'Otto', username: '@mdo' }, { id: 15, firstName: 'Lessie', lastName: 'Moe', username: '@lessie'} ]; changePage(event: any) { if (event.target.text >= 1 && event.target.text <= this.numberOfPaginators) { this.activePage = +event.target.text; this.firstVisibleIndex = this.activePage * this.itemsPerPage - this.itemsPerPage + 1; this.lastVisibleIndex = this.activePage * this.itemsPerPage; } } nextPage(event: any) { if (this.pages.last.nativeElement.classList.contains('active')) { if ((this.numberOfPaginators - this.numberOfVisiblePaginators) >= this.lastVisiblePaginator) { this.firstVisiblePaginator += this.numberOfVisiblePaginators; this.lastVisiblePaginator += this.numberOfVisiblePaginators; } else { this.firstVisiblePaginator += this.numberOfVisiblePaginators; this.lastVisiblePaginator = this.numberOfPaginators; } } this.activePage += 1; this.firstVisibleIndex = this.activePage * this.itemsPerPage - this.itemsPerPage + 1; this.lastVisibleIndex = this.activePage * this.itemsPerPage; } previousPage(event: any) { if (this.pages.first.nativeElement.classList.contains('active')) { if ((this.lastVisiblePaginator - this.firstVisiblePaginator) === this.numberOfVisiblePaginators) { this.firstVisiblePaginator -= this.numberOfVisiblePaginators; this.lastVisiblePaginator -= this.numberOfVisiblePaginators; } else { this.firstVisiblePaginator -= this.numberOfVisiblePaginators; this.lastVisiblePaginator -= (this.numberOfPaginators % this.numberOfVisiblePaginators); } } this.activePage -= 1; this.firstVisibleIndex = this.activePage * this.itemsPerPage - this.itemsPerPage + 1; this.lastVisibleIndex = this.activePage * this.itemsPerPage; } firstPage() { this.activePage = 1; this.firstVisibleIndex = this.activePage * this.itemsPerPage - this.itemsPerPage + 1; this.lastVisibleIndex = this.activePage * this.itemsPerPage; this.firstVisiblePaginator = 0; this.lastVisiblePaginator = this.numberOfVisiblePaginators; } lastPage() { this.activePage = this.numberOfPaginators; this.firstVisibleIndex = this.activePage * this.itemsPerPage - this.itemsPerPage + 1; this.lastVisibleIndex = this.activePage * this.itemsPerPage; if (this.numberOfPaginators % this.numberOfVisiblePaginators === 0) { this.firstVisiblePaginator = this.numberOfPaginators - this.numberOfVisiblePaginators; this.lastVisiblePaginator = this.numberOfPaginators; } else { this.lastVisiblePaginator = this.numberOfPaginators; this.firstVisiblePaginator = this.lastVisiblePaginator - (this.numberOfPaginators % this.numberOfVisiblePaginators); } } ngOnInit() { if (this.tableData.length % this.itemsPerPage === 0) { this.numberOfPaginators = Math.floor(this.tableData.length / this.itemsPerPage); } else { this.numberOfPaginators = Math.floor(this.tableData.length / this.itemsPerPage + 1); } for (let i = 1; i <= this.numberOfPaginators; i++) { this.paginators.push(i); } } }

API Reference:

In order to speed up your application, you can choose to import only the modules you actually need, instead of importing the entire MDB Angular library. Remember that importing the entire library, and immediately afterwards a specific module, is bad practice, and can cause application errors.

API Reference for MDB Angular Tables:
// MDB Angular Pro
import { WavesModule } from 'ng-uikit-pro-standard'