Using bDeferRender and registering event triggers

Using bDeferRender and registering event triggers

yedidelyedidel Posts: 2Questions: 1Answers: 0

Hello,

I have a large table (600 rows) that was loading very slowly with DataTable. I switched to JSON data input and used bDeferRender and it did cut a lot on loading time.

However, I now have another problem. In each row I have a checkbox with several triggers, for example when checkbox is clicked I have a function that does some things in the background.

Before I attached those triggers on $(document).ready and everything worked fine. Now however, because of the bDeferRender those input elements are created only when viewed, for example when switching to page in datatable, searching etc.

So I have put all triggers inside a ActivateTriggers() function and I launch it on fnDrawCallback, so all rows have their triggers attached when drawn.

My main problem now is that triggers get attached more than once. For example, if I have a row on the third page, the triggers are attached when I switch to page 3. Now if I use the filters to search for this row, the triggers get attached again (since the row is redrawn).

How can I ensure event triggers to attach only one for each row?

Answers

  • allanallan Posts: 65,431Questions: 1Answers: 10,865 Site admin

    Use delegated events, not fnDrawCallback . See the top FAQ.

    Allan

  • yedidelyedidel Posts: 2Questions: 1Answers: 0

    Thanks, but it doesn't work.
    All my events are registered using 'on', but they do not work after I switch a page

  • allanallan Posts: 65,431Questions: 1Answers: 10,865 Site admin

    $().on doesn't immediately mean that it is a delegated event. You need to use the format $(selector1).on( type, selector2, fn );.

    If that doesn't help, please link to a test case showing the problem.

    Allan

This discussion has been closed.