fnReloadAjax event handler cleanup after fnServerData and fnRowCallback are used

fnReloadAjax event handler cleanup after fnServerData and fnRowCallback are used

kidalexkidalex Posts: 10Questions: 0Answers: 0
edited October 2013 in General
I use fnServerData function to populate table with data. Then I modify one of the columns with fnRowCallback. Then I attach the "click" event using JQuery's "on" function to the modified column's contents.

My question is this: when this table is refreshed using fnReloadAjax - are the "on click" event handlers attached to the modified column's contents cleaned up from the DOM to avoid memory leaks?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Not by DataTables, since it doesn't know you've added them. You need to use either fnPreDrawCallback to remove them, or a much better solution would be to use a delegated event rather than static event handlers.

    Allan
  • kidalexkidalex Posts: 10Questions: 0Answers: 0
    Allan, how would one go about it? I need to have two different icons in a single cell that can have a tooltip ( by Bootstrap ) and also would be "clickable".
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Not sure I quite understand - you'd just use $({selector}).off('click') would you not?

    Allan
  • kidalexkidalex Posts: 10Questions: 0Answers: 0
    I ended up binding the events to the table's ID
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I think that's the best solution :-)

    Allan
This discussion has been closed.