在 Angular 5 Datatables 中出错:无法重新初始化 DataTable [英] Getting error in Angular 5 Datatables: cannot reinitialise DataTable
问题描述
我正在研究基于角度的项目.我正在使用数据表来显示数据.当我尝试对表进行一些修改时,出现以下错误.
I am working on the angular based project. I am using datatables to display data. When I try to do some modifications on the table, I get the following error.
DataTables 警告:table id=DataTables_Table_0 - 无法重新初始化 DataTable.有关此错误的详细信息,请参阅 http://datatables.net/tn/3
DataTables warning: table id=DataTables_Table_0 - Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3
推荐答案
我认为这是因为您在 Angular DataTables 中使用 [dtTrigger]=dtTrigger"
并在同一个表上重新渲染表页.如果你有这个问题,你应该使用下面的技巧来处理 dtTrigger
I think it is because you are using [dtTrigger]="dtTrigger"
in Angular DataTables and rerendering the table on the same page. If you have this problem you should use the following trick to handle dtTrigger
<table datatable [dtOptions]="dtOptions" [dtTrigger]="dtTrigger" class="table">
确保不要在 ngOnInit()
ngAfterViewInit(): void {
this.dtTrigger.next();
}
当你第二次使用时重新渲染
Rerender it when you use the second time
rerender(): void {
this.dtElement.dtInstance.then((dtInstance: DataTables.Api) => {
dtInstance.destroy();
this.dtTrigger.next();
});
}
这篇关于在 Angular 5 Datatables 中出错:无法重新初始化 DataTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!