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 warning: table id=DataTables_Table_0 - Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3
I solved this problem by removing the following code in *.ts file:
I am using DataTable in Angular7 and Bootstrap4
Step1: Install the package
npm i angular-datatables@6 datatables.net@1.10.19 datatables.net-dt@1.10.19 --save
Step2: In
angular.json
"styles": [ "./node_modules/datatables.net-dt/css/jquery.dataTables.css" ], "scripts": [ "node_modules/datatables.net/js/jquery.dataTables.js" ],
Step3: Inside
app.module.ts
Step4:
Inside html
Step5:
Inside ts
Step6: Inside your
controller api call
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 handledtTrigger
Make sure you do not use
this.dtTrigger.next()
onngOnInit()
Rerender it when you use the second time