ngx-datatables-net Modern Angular wrapper for DataTables.net

ngx-datatables-net

Modern Angular wrapper for DataTables.net

DataTables.net is a popular JavaScript library that turns a plain HTML table into one with sorting, search and pagination. This package lets you use it in an Angular app: you add the dtTable directive to a <table> and pass your data in. No jQuery to write, no setup beyond the steps below.

Angular wrapper maintained by Ascentspark.

Get started in five steps

New to Angular? First create an app: npm install -g @angular/cli then ng new my-app. Run every command below inside that project folder.

  1. 1

    Install the packages

    ngx-datatables-net is the wrapper. datatables.net is the underlying library, and datatables.net-dt is its default theme.

    Pick the line that matches your Angular version. The package API is the same across all three, so everything below works unchanged.

    npm install ngx-datatables-net@22 datatables.net datatables.net-dt
  2. 2

    Add the table stylesheet

    Open angular.json, find your app's "styles" array, and add the DataTables theme so the table looks right.

    "styles": [
      "node_modules/datatables.net-dt/css/dataTables.dataTables.css",
      "src/styles.scss"
    ]
  3. 3

    Register it in your app

    In src/app/app.config.ts, add the two providers below to the providers array. withSafeDefaults() escapes cell text so user data cannot inject HTML.

    import { ApplicationConfig, provideZonelessChangeDetection } from '@angular/core';
    import { provideDataTables, withSafeDefaults } from 'ngx-datatables-net';
    import { withDefaultStyling } from 'ngx-datatables-net/dt';
    
    export const appConfig: ApplicationConfig = {
      providers: [
        provideZonelessChangeDetection(),
        provideDataTables(withDefaultStyling(), withSafeDefaults()),
      ],
    };
  4. 4

    Add a table to a component

    Import DtTableDirective, put your rows in a signal, describe the columns, and add dtTable to a <table>.

    import { Component, signal } from '@angular/core';
    import { DtTableDirective, type ConfigColumns } from 'ngx-datatables-net';
    
    @Component({
      selector: 'app-people',
      imports: [DtTableDirective],
      template: `
        <table dtTable [dtData]="people()" [dtColumns]="columns"
               class="display" style="width:100%">
          <thead>
            <tr><th>Name</th><th>Role</th><th>City</th></tr>
          </thead>
        </table>
      `,
    })
    export class PeopleComponent {
      people = signal([
        { name: 'Ada Lovelace', role: 'Engineer', city: 'London' },
        { name: 'Linus Torvalds', role: 'Maintainer', city: 'Portland' },
      ]);
      columns: ConfigColumns[] = [
        { data: 'name', title: 'Name' },
        { data: 'role', title: 'Role' },
        { data: 'city', title: 'City' },
      ];
    }
  5. 5

    Run it

    Start the app with ng serve. You now have a sortable, searchable, paged table. To load different data later, just set a new array on the people signal. There is no manual refresh step.

See the live basic table or browse the examples in the sidebar for data sources, features, styling and every DataTables extension.

Frequently asked questions

Does ngx-datatables-net require jQuery?

You never write jQuery. The library uses DataTables’ non-jQuery API. DataTables itself still uses jQuery internally, so it sits in your dependency tree as a transitive dependency of datatables.net, but it never appears in your own code.

Which Angular versions are supported?

Angular 20, 21 and 22. There is one package major per Angular major: install 22.x for Angular 22 (npm tag latest), 21.x for Angular 21 (ng21), and 20.x for Angular 20 (ng20).

How do I reload the table with new data?

Assign a new array to the dtData signal input. The directive reconciles the table automatically (clear, add rows, redraw) and keeps the current page and sort. There is no manual trigger like the old dtTrigger Subject.

Do I need NgModules or Zone.js?

No. The directive is standalone and works under zoneless change detection, which is the default in Angular 21 and 22. It also runs fine in zoned apps.

How do I avoid XSS when showing user data?

Add withSafeDefaults() to provideDataTables(). It escapes every column that has no explicit renderer, which overrides DataTables’ unsafe HTML-by-default behavior. To render HTML on purpose, use the DomSanitizer-backed renderer the library provides.

Does it support Ajax and server-side processing?

Yes. Set the ajax option for client-side loading, or serverSide: true with an ajax function that posts the paging, sort and search parameters to your API. The directive passes the full DataTables config through.

Which DataTables extensions work?

All of them, with no library-specific code: Buttons, Select, ColumnControl, Responsive, FixedHeader, FixedColumns, Scroller, RowGroup, RowReorder, ColReorder, SearchPanes, SearchBuilder, KeyTable, AutoFill, DateTime and StateRestore. Import the extension package and configure it through dtOptions. The commercial Editor is compatible via the exposed Api.

Can I use it with server-side rendering (SSR)?

Yes. The table initialises in the browser only (via afterNextRender), so the server renders plain table markup and the table is enhanced on the client during hydration.