Angular Bootstrap table search

Angular Table search - Bootstrap 4 & Material Design

Angular Bootstrap table search are a component which are super fast and easy to use searching functionality dedicated to our tables.

To manipulate table search use one of the options presented below.


Basic example

Live example

        <div class="container">
          <div class="row">
            <div class="col-md-12 mx-auto">
              <div class="md-form">
                <input type="text" [(ngModel)]="searchText" class="form-control" id="search" mdbInput>
                <label for="search">Search</label>
              </div>
            </div>
          </div>
          <table mdbTable class="z-depth-1">
            <thead>
            <tr>
              <th *ngFor="let head of headElements; let i = index" scope="col">{{head}}
              </th>
            </tr>
            </thead>
            <tbody>
            <tr *ngFor="let el of elements; let i = index">
              <th scope="row">{{el.id}}</th>
              <td class="red-text">{{el.first}}</td>
              <td>{{el.last}}</td>
              <td>{{el.handle}}</td>
            </tr>
            </tbody>
          </table>
        </div>
      

        import {Component, HostListener, ViewChild} from '@angular/core';
        import {MdbTableDirective} from "PATH-TO-MDB-ANGULAR";

        @Component({
          selector: 'search-table',
          templateUrl: './search-table.component.html',
          styleUrls: ['./search-table.component.scss']
        })
        export class SearchTableComponent {
          @ViewChild(MdbTableDirective) mdbTable: MdbTableDirective;
          elements: any = [];
          headElements = ['ID', 'First', 'Last', 'Handle'];

          searchText: string = '';
          previous: string;

          constructor() { }

          @HostListener('input') oninput() {
            this.searchItems();
          }

          ngOnInit() {
            for (let i = 1; i <= 10; i++) {
              this.elements.push({ id: i.toString(), first: 'Wpis ' + i, last: 'Last ' + i, handle: 'Handle ' + i });
            }

            this.mdbTable.setDataSource(this.elements);
            this.elements = this.mdbTable.getDataSource();
            this.previous = this.mdbTable.getDataSource();
          }

          searchItems() {
            const prev = this.mdbTable.getDataSource();

            if (!this.searchText) {
              this.mdbTable.setDataSource(this.previous);
              this.elements = this.mdbTable.getDataSource();
            }

            if (this.searchText) {
              this.elements = this.mdbTable.searchLocalDataBy(this.searchText);
              this.mdbTable.setDataSource(prev);
            }
          }
        }

      

Advanced table options

For advanced options of the tables have a look at specific documentation pages listed below.

Table sort

This functionality lets you sort the data of the tables according to any specific columns.

Table editable

Table editable allows you to edit existing data within the table and add new data to the table.

Table pagination

Table with pagination allows you to paginate through your data in the tables

Angular Datatables - API

In this section you will find advanced information about the Table component. You will find out which modules are required in this component, what are the possibilities of configuring the component, and what events and methods you can use in working with it.

Modules used

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.

                    
              // MDB Angular Pro
              import { WavesModule, TableModule, InputsModule } from 'ng-uikit-pro-standard';

              // MDB Angular Free
              import { WavesModule, TableModule, InputsModule } from 'angular-bootstrap-md';

              // Angular Forms
              import { FormsModule } from '@angular/forms';
                    
                  

Directive

MdbTableDirective

Selector: mdbTable

Export as: mdbTable

Type: MdbTableDirective


Methods

Name Description Example
setDataSource(source: Array<any>) It is used to indicate service an array that stores the data contained in the table. The use of this method is required for the use of results filtering. this.tableService.setDataSource(this.elements)
getDataSource() The method returns an array that has been indicated as the data source of the table. The use of this method is required to filter the results. this.elements = this.tableService.getDataSource()
searchLocalDataBy(searchText: string) The method starts filtering the source array by the character provided as its parameter. The use of this method is required to be able to filter the results. this.elements = this.tableService.searchLocalDataBy(this.searchText)