fnDrawCallback does not work propertly

fnDrawCallback does not work propertly

didvaedidvae Posts: 6Questions: 0Answers: 0
edited February 2012 in DataTables 1.9
I'm using multiple selecting rows, when table is loaded, I can select and unselect rows, but if I do pagination or sorting(repaint the page), then I cannot select rows, if I change page again, I can do it. I thought that fnDrawCallback is executed every time table is painted, but seems to be executes ones yes, ones no, once yes, once no ...

I add this to dataTables config:[code]"fnDrawCallback": function() {
$('.dataTable tr').click( function() {
$(this).toggleClass('row_selected');
});
}[/code]

thanks in advance

Replies

  • didvaedidvae Posts: 6Questions: 0Answers: 0
    It's a bit strange, every time I redraw the table, the event is executed one more time, ex. First time table is loaded, callback is executed one, next time 2, next time 3 times, ...
  • allanallan Posts: 63,493Questions: 1Answers: 10,470 Site admin
    Yup - fnDrawCallback is called every time the table does a redraw - which is way you are seeing your events being added multiple times.

    There are a number of options - the more obvious I would say is to use a live / delegated event: http://datatables.net/faqs#events .

    The other option is to use the $API method:

    [code]
    oTable.$('tr').click( function () { ... } );
    [/code]

    the $ function will give you a jQuery object to operate on all TR elements in the table's body.

    Allan
  • didvaedidvae Posts: 6Questions: 0Answers: 0
    Thanks Allan, using $API works fine for me
This discussion has been closed.