bDestroying flag is not reset when datatable is reinitialised, using destroy

bDestroying flag is not reset when datatable is reinitialised, using destroy

mcauleytmcauleyt Posts: 1Questions: 1Answers: 0

Hi,

This may be a bug or bad coding on our side.

The scenario is:

  • A table, using dataTables is created, with pre-filled data (no ajax)
  • Each of the columns has a search filter.
  • When the page is loaded, each of the search filter input fields is populated from the dataTable settings.
  • When a data row is clicked, an editable dialog is displayed, allowing the user to edit the data and then choose save.
  • Upon saving, the div containing the table is redrawn using ajax (not datatable ajax source). The datatable is reinitialised. The bDestroy flag is set to true.
  • After the dialog has been opened and closed and the table redrawn, the column filtering is still working BUT the settings for sSearch on each column are not updated. This means that if the page is reloaded, the filtering options are lost.

Using a storage viewer in Firefox (FireStorage Plus), we noticed that after the dialog was opened and closed, the sSearch setting was not being updated. The table was still being filtered but the settings weren't updated. Incidentally, If you reorder the table by any column, the order setting is saved ok.

After looking through the code of jquery.dataTables.js, we noticed there was a check to see if bDestroying was set or not. This flag was set to false always, after a datatable was reinitialised (destroyed and re-created?); thus the column filter setting was not being saved.

We have implemented the following fix (or hack?):

  • In the destroy function: _api_register( 'destroy()', function ( remove ) {
  • There is a line saying settings.bDestroying = true;.
  • We have added the following at the end of the table iterator, near the end of the function. settings.bDestroying = false;

Any feedback on this would be appreciated. Is this a bug or are we doing something wrong which means we're holding onto an old instance of settings (haven't found it so far).

I do not have a test harness for this yet but may be able to produce one in a few days when work is quieter.

Thanks for an amazing plugin btw! Keep up the good work.

Tim

This discussion has been closed.