Hitendra Patil
Hitendra Patil

Reputation: 37

Angular Datatable- paging not getting refresh while updating table second time in angular 5

I am using angular data-table https://l-lin.github.io/angular-datatables/#/welcome.

After calling API on page load data table works fine.But when I updated table second time then I am facing some problem like:

1) data getting displayed but Showing entries not updated like Showing 1 to 5 of 5 entries.It should be " Showing 1 to 1 of 1 entries " for second time instead of " Showing 1 to 5 of 5 entries "

2) When I search for particular record then it's search record in previous data not with current data.

So I tried some solution like

When updating data second time then I destroy first data table instance and then again rendered the data table. For that I had wrote the function like

rerender(): void {
 THAT.datatableElement.dtInstance.then((dtInstance: DataTables.Api) => {
  // Destroy the table first
  dtInstance.destroy();
  // Call the dtTrigger to rerender again
  THAT.dtTrigger.next();
 });
}

Upvotes: 1

Views: 2362

Answers (1)

Midhun P
Midhun P

Reputation: 126

use below method to rebind datatable ie, this.rebindDataTable();

rebindDataTable() {
        this.datatableElement.dtInstance.then(x => x.draw());
}

Upvotes: 2

Related Questions