angular - Angular Datatable-在角度 5 中第二次更新表时没有刷新
问题描述
我正在使用角度数据表https://l-lin.github.io/angular-datatables/#/welcome。
在页面加载数据表上调用 API 后工作正常。但是当我第二次更新表时,我遇到了一些问题,例如:
1) 数据显示但显示条目未更新,如 Showing 1 to 5 of 5 entries.It 应该是“显示 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());
}
推荐阅读
- python - R:大熊猫(Python)的df.info()是否有R等价物?
- python - 如何使用networkx查找强连接组件的子图
- spartacus-storefront - 覆盖页面模板,子组件从活动路由中丢失
- chart.js - 页面上的两个chartjs图表抛出数据未定义错误
- python - TypeError:“NoneType”对象不能用 bs4 下标
- python - 比较python中的两个列表
- c# - 允许文本换行和平滑滚动的 Winforms 控件
- javascript - VueJS - 羽毛图标的无效渲染
- laravel - Laravel 混合夹板块供应商
- google-apps-script - 触发谷歌表格