Angular 13 datatable example with pagination sorting filtering

In this tutorial, we will learn how to create a table with pagination, sorting, and filtering using datatables in an Angular 13 application.

  • Step 1 – Create New Angular App
  • Step 2 – Install jQuery & DataTable Plugins
  • Step 3 – Import Module.ts File
  • Step 4 – Create HTML Table on View File
  • Step 5 – Add Code On Component ts File
  • Step 6 – Start Angular App

Step 1: Create a new Angular 13 app

To get started, open your terminal and run the following command to create a new Angular 13 app:

ng new my-new-app

Step 2: Install jQuery and Datatables plugins

Next, you need to install the required NPM packages for implementing datatables in Angular apps. Run the following commands on your terminal to install the necessary packages:

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

After the packages are installed, open the angular.json file and add the following code in the styles and scripts sections:

"styles": [
"scripts": [

Step 3: Import the required modules

In the app.module.ts file, add the following code to import the required modules:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { DataTablesModule } from 'angular-datatables';
import { HttpClientModule } from '@angular/common/http';
import { AppComponent } from './app.component';

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

Step 4: Create the HTML table

In the app.component.html file, create an HTML table to display the dynamic data:

<h1>Angular 13 Datatables Example -</h1>
<table datatable [dtOptions]="dtOptions" class="row-border hover">
    <tr *ngFor="let post of posts">
      <td>{{ }}</td>
      <td>{{ post.title }}</td>
      <td>{{ post.body }}</td>

Step 5: Add code to the component ts file

In the app.component.ts file, add the following code to set up the datatable:

import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';

  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
export class AppComponent implements OnInit{
  title = 'datatables';
  dtOptions: DataTables.Settings = {};

  constructor(private http: HttpClient) { }

  ngOnInit(): void {
    this.dtOptions = {
      pagingType: 'full_numbers',
      pageLength: 5,
      processing: true

      .subscribe(posts => {
        this.posts = posts;

Step 6: Start the Angular app

Finally, run the following command on your terminal to start the Angular app:

ng serve

That’s it! You should now see the table with pagination, sorting, and filtering in your Angular 13 app.