Im having Error after destroying DataTable
Im having Error after destroying DataTable
therencepogi
Posts: 2Questions: 1Answers: 0
"Uncaught TypeError: Cannot read property 'length' of undefined " after i destroy() it. im using serverside datatable this is my sample code"
load_customers(){
if( typeof dt != 'undefined'){
dt.destroy();
dt.empty();
}
dt = $('#customers-table').DataTable( {
"processing": true,
"serverSide": true,
"ajax": url+'customers/load_customers',
"destroy" : true,
"columns": [
{
"class": "details-control",
"orderable": false,
"data": null,
"defaultContent": "",
"width": "5%"
},
{ "data": 1},
{ "data": 2 },
{ "data": 3 },
{ "data": 4, "width": "5%" , bSortable: false},
{ "data": 5, "width": "20%" , bSortable: false}
],
"order": [[1, 'DESC']]
} );
}
This discussion has been closed.
Answers
That suggests that
url+'customers/load_customers'
is not returning the expected JSON format for server-side processing, but we'd need a test case to be sure.Allan
Hi Allan.
thank you for your help.
Just found out the problem or bug
The error occurs after i click the details
(hide and show - based it here https://datatables.net/examples/server_side/row_details.html)
then destroy the datatable
Thanks
If I load that page, show a details row and then run
$('#example').DataTable().destroy()
in the console, it correctly destroys the table and no errors occur.The row icon still shows as red, but that's because that isn't DataTables controlled, so other code would be needed to remove it (since
destroy()
) doesn't know anything about it.Allan