From c625f2f5254cf0e48924fe28b3dc8b1936e58f94 Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Thu, 20 Mar 2014 15:19:26 +0000 Subject: [PATCH] Fix: Destroy should use `detatch()` not `remove()` - This is to preserve user added listeners on destroy. If they want to remove their listeners to prevent memory leaks, then they should do so. But DataTables won't do it for them, as actually, you might want to keep your event listeners! --- .datatables-commit-sync | 2 +- media/js/jquery.dataTables.js | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.datatables-commit-sync b/.datatables-commit-sync index 891685ff..c86b5543 100644 --- a/.datatables-commit-sync +++ b/.datatables-commit-sync @@ -1 +1 @@ -fb8a718af86bdcb880606e67c30bd118e3efd174 +d8efc98282583e4661bb38af9449f0fa4bb79996 diff --git a/media/js/jquery.dataTables.js b/media/js/jquery.dataTables.js index 2d35f724..e8be88af 100644 --- a/media/js/jquery.dataTables.js +++ b/media/js/jquery.dataTables.js @@ -8548,24 +8548,26 @@ new _Api( settings ).columns().visible( true ); } - // Blitz all DT events + // Blitz all `DT` namespaced events (these are internal events, the + // lowercase, `dt` events are user subscribed and they are responsible + // for removing them jqWrapper.unbind('.DT').find(':not(tbody *)').unbind('.DT'); $(window).unbind('.DT-'+settings.sInstance); // When scrolling we had to break the table up - restore it if ( table != thead.parentNode ) { - jqTable.children('thead').remove(); + jqTable.children('thead').detach(); jqTable.append( thead ); } if ( tfoot && table != tfoot.parentNode ) { - jqTable.children('tfoot').remove(); + jqTable.children('tfoot').detach(); jqTable.append( tfoot ); } // Remove the DataTables generated nodes, events and classes - jqTable.remove(); - jqWrapper.remove(); + jqTable.detach(); + jqWrapper.detach(); settings.aaSorting = []; settings.aaSortingFixed = []; @@ -8578,11 +8580,11 @@ ); if ( settings.bJUI ) { - $('th span.'+classes.sSortIcon+ ', td span.'+classes.sSortIcon, thead).remove(); + $('th span.'+classes.sSortIcon+ ', td span.'+classes.sSortIcon, thead).detach(); $('th, td', thead).each( function () { var wrapper = $('div.'+classes.sSortJUIWrapper, this); $(this).append( wrapper.contents() ); - wrapper.remove(); + wrapper.detach(); } ); }