1
0
mirror of https://github.com/DataTables/DataTables.git synced 2024-12-01 13:24:10 +01:00

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!
This commit is contained in:
Allan Jardine 2014-03-20 15:19:26 +00:00
parent 90870af5ac
commit c625f2f525
2 changed files with 10 additions and 8 deletions

View File

@ -1 +1 @@
fb8a718af86bdcb880606e67c30bd118e3efd174 d8efc98282583e4661bb38af9449f0fa4bb79996

View File

@ -8548,24 +8548,26 @@
new _Api( settings ).columns().visible( true ); 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'); jqWrapper.unbind('.DT').find(':not(tbody *)').unbind('.DT');
$(window).unbind('.DT-'+settings.sInstance); $(window).unbind('.DT-'+settings.sInstance);
// When scrolling we had to break the table up - restore it // When scrolling we had to break the table up - restore it
if ( table != thead.parentNode ) { if ( table != thead.parentNode ) {
jqTable.children('thead').remove(); jqTable.children('thead').detach();
jqTable.append( thead ); jqTable.append( thead );
} }
if ( tfoot && table != tfoot.parentNode ) { if ( tfoot && table != tfoot.parentNode ) {
jqTable.children('tfoot').remove(); jqTable.children('tfoot').detach();
jqTable.append( tfoot ); jqTable.append( tfoot );
} }
// Remove the DataTables generated nodes, events and classes // Remove the DataTables generated nodes, events and classes
jqTable.remove(); jqTable.detach();
jqWrapper.remove(); jqWrapper.detach();
settings.aaSorting = []; settings.aaSorting = [];
settings.aaSortingFixed = []; settings.aaSortingFixed = [];
@ -8578,11 +8580,11 @@
); );
if ( settings.bJUI ) { 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 () { $('th, td', thead).each( function () {
var wrapper = $('div.'+classes.sSortJUIWrapper, this); var wrapper = $('div.'+classes.sSortJUIWrapper, this);
$(this).append( wrapper.contents() ); $(this).append( wrapper.contents() );
wrapper.remove(); wrapper.detach();
} ); } );
} }