How to use angular datatable

How to use angular datatable

In this article lets understand how to use angular datatable.

A third-party library called Angular DataTables connects Angular to the well-liked DataTables jQuery plugin. Sorting, searching, pagination, and other capabilities make it simple to display and interact with data in tabular form. By offering an effective solution to handle massive datasets and displaying them in a user-friendly fashion, DataTables improves the user experience.

Key features of Angular DataTables:

  1. Data Presentation
  2. Searching
  3. Pagination
  4. Filtering
  5. Styling and Theming
  6. Customization
  7. Responsiveness.

Lets follow step-by-step guide:

1) Install dependencies

First, we will need the required packages from npm. Run below command from terminal in the project directory :

npm install jquery --save
npm install --save
npm install --save
npm install angular-datatables --save
npm install @types/jquery --save-dev
npm install @types/ --save-dev
npm install bootstrap --save

We will need to add styles and script in our angular.json as below :

            "styles": [

            "scripts": [


2) Import modules

Add required modules from above added libraries into app.modues.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { DataTablesModule } from 'angular-datatables';

import { AppComponent } from './app.component';

  declarations: [AppComponent],
  imports: [BrowserModule, DataTablesModule],
  bootstrap: [AppComponent]
export class AppModule { }

3) Set datatable in component :

Next let’s set datatable html in our components html file.

<table datatable [dtOptions]="dtOptions" [dtTrigger]="dtTrigger" class="table table-striped table-bordered">
    <tr *ngFor="let user of users">
      <td>{{ }}</td>
      <td>{{ user.age }}</td>
      <td>{{ }}</td>

4) Configure datatable :

Now we will configure datatable in our components ts file as below.

import { Component, OnInit, ViewChild } from '@angular/core';
import { Subject } from 'rxjs';
import { DataTableDirective } from 'angular-datatables';

  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
export class AppComponent implements OnInit {
  @ViewChild(DataTableDirective, { static: false })
  private datatableElement: DataTableDirective;
  dtOptions: DataTables.Settings = {};
  dtTrigger: Subject<any> = new Subject<any>();
  users = [
    { name: 'Richard', age: 45, email: '' },
    { name: 'Joey', age: 25, email: '' },
  ngOnInit(): void {
    this.dtOptions = {
      pagingType: 'full_numbers',
      pageLength: 10
      // You can add more options as needed
    setTimeout(() => {;
    }, 0);
  ngOnDestroy(): void {

Datatable provides many options which we will see in our other blogs in detail.

You can set dynamic data from apis and reflect as above.

5) Result :

The above one will give result as below:

Angular datatable result

That’s it on how to use angular datatable. Hope this finds you helpful.

Read more articles on angular here.