Press "Enter" to skip to content

Datatables warning: table id = ‘table_id’ – cannot reinitialise DataTable [Resolved]

This is because you reinitialize the datatable again.

Before you reinitialize, you need to destroy existing one.

Try this code:

$('#table_id').dataTable({
            "bDestroy": true
        }).fnDestroy();


$('#table_id').DataTable( {      
        autoWidth: false, 
        columnDefs: [
            { width: '300px', targets: 0 }, 
            { width: '300px', targets: 0 },            
        ]
    } ); 

Explanation:

$(‘#table_id’).dataTable({
“bDestroy”: true
}).fnDestroy();

This code destroy existing one.

$(‘#table_id’).DataTable( {
autoWidth: false,
columnDefs: [
{ width: ‘300px’, targets: 0 },
{ width: ‘300px’, targets: 0 },
]
} );

This code is initiation of datatable with table id and other table properties.

Be First to Comment

Leave a Reply