Reputation: 37
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
Reputation: 126
use below method to rebind datatable ie, this.rebindDataTable();
rebindDataTable() {
this.datatableElement.dtInstance.then(x => x.draw());
}
Upvotes: 2