Hello together,
I need some help using datatables. Loading a datatable works fine. But now I have to change data inside the table. I learned , that once a table is initialised, it is not possible to change data so easy.
The html code:
<table id="tableId" class="table table-striped display text-right" role="grid" style="width: 100%">
My javascript code is:
$(tableId).DataTable(data);
Filling the table works fine. But with updating the table, I get following error:
DataTables warning: table id=tableId- Cannot reinitialise DataTable. For more information about this error, please see
http://datatables.net/tn/3
I tried to look for an answer. So far I found something about destroy() but nothing works. I guess it is a simple solution, but... How can I clear the whole table and reinizialise it with new data.
I tried following (found here in the forum):
let table = document.getElementById(tableId);
// clear first
if(table!=null){
table.clear();
table.destroy();
}
//2nd empty html
$(tableId + " tbody").empty();
$(tableId + " thead").empty();
//3rd reCreate Datatable object
$(tableId).DataTable(data);
But I always get the above failure message.
Would be happy for some help