link event after filtering datatables

link event after filtering datatables

rodblochonrodblochon Posts: 2Questions: 1Answers: 0

Hi everyone

I have datatabled my table with the filter input and a pagination in the DOM.
On each row, I have a button with a particular #id that I can click to throw an ajax call (depending on this #id).
but this only works on the row of the first page.

If my row is not on the first page either when I change the page or I use the filter input, the ajax call is not launched.
I bind the click on the button with :
$('#theButton').on('click',function(){
console.log($(this).attr('id');
});

As I said, it works only with the first-page results...

I don't understand why while I looked for fixing the problem on forums (this forum, github and so on...)
I'm not an expert developper, I do that for fun but right now my app is not working well

thank you all for your help!
rod

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin
    Answer ✓

    Hi Rod,

    Most likely you need to use a delegated event, as shown in this example.

    I assume your button id is unique on every row? Each id must be unique in an HTML page.

    Allan

  • rodblochonrodblochon Posts: 2Questions: 1Answers: 0

    thank you Allan.
    with the keywords "delegated events" and the example you gave, now it works nicely !!

Sign In or Register to comment.