Cannot reinitialize Datatable after updating data
Cannot reinitialize Datatable after updating data
Link to test case: https://bigwebuy.com/flora/colecciones
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem: I cannot reinitialize my dataTables after updating its content. I have a form that searches in the database and updates the results in the table, and then initializes DataTable. My code looks like this:
when submitting the search form (clicking on "Buscar" button) I first check if there is already a table initialized with the following code, and if so, I clear it and destroy it to avoid the cannot reinitialize Datatable error:
if ( DataTable.isDataTable( '.dataTable' ) ) {
$('.dataTable').DataTable().clear().destroy();
}then I take the data retrieved by an ajax call, and add new <tr> elements with the results. Then call my custom initialize_datatable() function. On the first time, it initializes the Datatable correctly
when making a new search (expanding the form again with "+ Buscar colecciones") I try to follow the same procedure, but the table won't reinitialize. The datatable gets correctly destroyed, and new results are added to the table as <tr> elements, but I cannot initialize it again. Even when trying to initialize the table with the console by second time, it won't do it.
Any help is appreciated !
Answers
Just realized where my problem was .. the fact that the datatables library was removing my "datatable" class after initializing it. Sorry about that
No worries - thanks for posting back - good to hear you've got it resolved!
Allan