Im having Error after destroying DataTable

Im having Error after destroying DataTable

therencepogitherencepogi 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']]
    } );
 
}

Answers

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    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

  • therencepogitherencepogi Posts: 2Questions: 1Answers: 0

    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

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    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

This discussion has been closed.