TableTools bug when .fnDestroy()'ing and re-initializing table.

TableTools bug when .fnDestroy()'ing and re-initializing table.

joeltinejoeltine Posts: 4Questions: 0Answers: 0
edited March 2012 in Bug reports
Im using DT 1.9 and TableTools 2.0.2.

I found a bug when trying to fnDestroy and remove a table w/ TableTools from the DOM, then re-initialize it. The Table is initialized with TableTools in both circumstances. TableTools is initialized using a button collection. I couldn't create a jsfiddle example because they don't allow flash.

The error occurs on line 133 of ZeroClipboard.js, "Unable to call appendChild on null":

this.domElement.parentNode.appendChild(this.div);

I think its because div.DTTT_collection isn't getting removed from the page when you destroy the table. So when you re-initialize it, it finds the existing .DTTT_collection buttons and tries to reuse it. I made a temporary fix by adding after my fnDestroy:

$(".DTTT_collection").remove();

right after I destroy and .remove() the table element. This seems to work.

Cheers.

P.S. If it helps here is the options I"m using for TableTools:
[code]
"sDom": 'TC<"clear"><"H"lfr>t<"F"ip>',
"oTableTools": {
"sSwfPath": "../js/jquery/datatables/TableTools/media/swf/copy_cvs_xls_pdf.swf",
"aButtons": [
{
"sExtends": "collection",
"aButtons": ['csv', 'pdf','xls' ]
}
]
}
[/code]

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Hi - thanks for flagging this up! Great to hear you've got a work around for the moment, and I've made a note to fix this in TableTools. It needs to listen for the destroy event from DataTables and then clean itself up... :-)

    Regards,
    Allan
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    An old post I know, but I'm going through my to-do list at the moment to get DataTables ready for 1.9.1, and I want to include an updated TableTools in that release. I've just fixed this issue and it will be in the 2.0.3 TableTools release. The problem was that the table could be removed from the DOM before the Flash movie reports ready at which point it would try to bind to an element that has been removed from the DOM - hence the error.

    Allan
This discussion has been closed.