1
0
mirror of https://github.com/DataTables/DataTables.git synced 2025-01-18 11:52:11 +01:00

Fix: Memory leaks from not removing listeners on destroy

- DataTables uses the `DT` namespace for events internally and will
  remove them automatically on destroy, but `dt` is used for public
  events. As such, the public events used internally should use `.dt.DT`
  to ensure that the listener works as expected, but also so that the
  destroy call will remove these listeners
This commit is contained in:
Allan Jardine 2014-03-20 15:19:42 +00:00
parent c625f2f525
commit 67a2b18ca3
2 changed files with 8 additions and 5 deletions

View File

@ -1 +1 @@
d8efc98282583e4661bb38af9449f0fa4bb79996
c672ef3563ffb4e8287d510c8088914114c58a52

View File

@ -3142,7 +3142,7 @@
} );
// Update node value whenever anything changes the table's length
$(settings.nTable).bind( 'length', function (e, s, len) {
$(settings.nTable).bind( 'length.dt.DT', function (e, s, len) {
select.val( len );
} );
@ -13879,8 +13879,11 @@
header: {
_: function ( settings, cell, column, classes ) {
// No additional mark-up required
// Attach a sort listener to update on sort
$(settings.nTable).on( 'order.dt', function ( e, settings, sorting, columns ) {
// Attach a sort listener to update on sort - note that using the
// `DT` namespace will allow the event to be removed automatically
// on destroy, while the `dt` namespaced event is the one we are
// listening for
$(settings.nTable).on( 'order.dt.DT', function ( e, settings, sorting, columns ) {
var colIdx = column.idx;
cell
@ -13909,7 +13912,7 @@
.appendTo( cell );
// Attach a sort listener to update on sort
$(settings.nTable).on( 'order.dt', function ( e, settings, sorting, columns ) {
$(settings.nTable).on( 'order.dt.DT', function ( e, settings, sorting, columns ) {
cell
.removeClass( classes.sSortAsc +" "+classes.sSortDesc )
.addClass( columns[ colIdx ] == 'asc' ?