fnDestroy and side-effects

fnDestroy and side-effects

keturnketurn Posts: 18Questions: 0Answers: 0
edited November 2011 in Bug reports
I'm reviewing some code that uses DataTables 1.8.1 and fnDestroy, and I came across a few issues:

1) fnDestroy does a number of things to return the table to its pre-datatables state. In at least one use here, we want to destroy the table entirely, and are calling fnDestroy to make sure its data is freed. But all the work fnDestroy does to restore hidden columns and the original TR elements is wasted effort if we just go on to remove the table itself. (I haven't profiled this yet, maybe it's not a real problem, but there is at least one loop over aoData in there.)

2) The thing that took me a long time to debug was that we'd hidden the div#table_wrapper, and when fnDestroy put the table back on the parentNode, it was no longer hidden. On the one had, it seems like it'd be out of scope for DT to track all changes to the wrapper element, on the other, it was a surprising behaviour that sucked to track down. (Perhaps the right answer is for us to not manipulate dt's table_wrapper at all, but it seemed like the straightforward way to hide the table at the time.)

Replies

  • allanallan Posts: 63,383Questions: 1Answers: 10,449 Site admin
    Hi,

    Thanks very much for the feedback. Both very good points:

    1. Agreed, its is wasted effort if you then just go ahead and remove all the elements, but at the same time is might be desired behaviour for some other tables. Thus to offer both there would need to be an option to pass into fnDestroy - which leads on to point 2:

    2. The intention of fnDestroy was to return the table to its previous state - it wasn't really a design goal of the function to facilitate completely removing the table, although in retrospect, that should have been a fairly obvious enhancement for me to have put in!

    So what I think I'll do is modify fnDestroy to take an optional parameter which does a complete destroy and remove of the table, without you needing to put any code around it to cope with its eccentricities...

    I can't do this right at the moment as I'm in the middle of making some fairly big structural changes to how DataTables is built (although not functional changes at the moment) and I'd like to finish that off first. But I've got a note of this to add it when that work is finished and it will be in the next release (1.9).

    Regards,
    Allan
  • allanallan Posts: 63,383Questions: 1Answers: 10,449 Site admin
    Just committed a change for this. fnDestroy will take 1 option parameter which when set to true will cause the table to be completely removed from the DOM.

    This will be in the 1.9 beta which should be out soon(ish) :-)

    Allan
This discussion has been closed.