I am working with datatables example and getting an error like this when loading page: Datatables warning(table id = \'example\'): cannot reinitialise data table. To retriev
Try adding "bDestroy": true to the options object literal, e.g.
$('#dataTable').dataTable({
...
....
"bDestroy": true
});
Source: iodocs.com
or Remove the first:
$(document).ready(function() {
$('#example').dataTable();
} );
In your case is the best option vjk.
You can add destroy:true
to the configuration to make sure data table already present is removed before being reinitialized.
$('#example').dataTable({
destroy: true,
...
});
This problem occurs if we initialize dataTable more than once.Then we have to remove the previous.
On the other hand we can destroy the old datatable in this way also before creating the new datatable use the following code :
$(“#example”).dataTable().fnDestroy();
There is an another scenario ,say you send more than one ajax request which response will access same table in same template then we will get error also.In this case fnDestroy method doesn’t work properly because you don’t know which response comes first or later.Then you have to set bRetrieve TRUE
in data table configuration.That’s it.
This is My senario:
<script type="text/javascript">
$(document).ready(function () {
$('#DatatableNone').dataTable({
"bDestroy": true
}).fnDestroy();
$('#DatatableOne').dataTable({
"aoColumnDefs": [{
"bSortable": false,
"aTargets": ["sorting_disabled"]
}],
"bDestroy": true
}).fnDestroy();
});
</script>
When searching this topic I found the solution elsewhere but adding the answer here since I had the same problem as above together with the text "Uncaught TypeError: Cannot set property '_DT_CellIndex' of undefined". Cause was due to having one to many tags in the table body.
I know its an old question. This problem can be easily reproduced if you try to reinitialize the Datatable again.
For example in your function somewhere you are calling $('#example').DataTable( { searching: false} );
again.
There is easy resolving this issue. Please follow the steps
$('#example').DataTable( { searching: false} );
try to declare it globally (or in scope of javascription that you are using) like this var table = $('#example').DataTable( {
searching: false
} );
.$('#example').DataTable( { searching: false} );
again then before calling it perform the following actions
if (table != undefined && table != null)
{
table.destroy();
table = null;
}
table = $('#example').DataTable( {
searching: false
} );
JSFiddle Code Also attached for any reference of same code http://jsfiddle.net/vibs2006/qxy4nwfg/
In my case the ajax call was being interfered by the data-plugin tag applied to the table. The data-plugin does background initialization and will give this error when you have it as well as yourTable.DataTable({ ... }); initialization.
From
<table id="myTable" class="table-class" data-plugin="dataTable" data-source="data-source">
To
<table id="myTable" class="table-class" data-source="data-source">