角度数据表 - 在角度 5 中第二次更新表时分页未刷新



我正在使用角度数据表 https://l-lin.github.io/angular-datatables/#/welcome。

在页面加载数据表上调用 API 后工作正常。但是当我第二次更新表格时,我遇到了一些问题,例如:

1) 显示数据但显示条目未更新,例如显示 5 个条目中的 1 到 5。它应该是"第二次显示 1 到 1 的 1 个条目",而不是"显示 1 到 5 个条目中的 5 个条目"

2)当我搜索特定记录时,它是以前数据中的搜索记录,而不是当前数据。

所以我尝试了一些解决方案,例如

第二次更新数据时,我销毁第一个数据表实例,然后再次呈现数据表。为此,我编写了这样的函数

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

使用以下方法重新绑定数据表,即this.rebindDataTable();

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

最新更新