AJAX source with click listeners

AJAX source with click listeners

shauntainshauntain Posts: 6Questions: 0Answers: 0
edited January 2010 in General
Hello,

In my script I am using an AJAX source to constantly get new items. I am not using the datatable built in function because I am passing a lot of other information that I want to use.

Currently I am downloading the information and clearing the table. Then I add the items back using fnAddData(string, false). Then I redraw the table and use the fnDrawCallback to add click listeners to my items.

The problem is that when I go from say page 1 -> page 2 then back to page 1 I will have 2 click listeners on page 1's items.

So I am wondering how do I add click listeners to all my items in my table only once? I tried fnRowCallback but it added x listeners to each of my x items. Maybe I was using it wrong.

Thanks.

Replies

  • allanallan Posts: 63,695Questions: 1Answers: 10,500 Site admin
    Hi shauntain,

    fnAddData will return an array of indexes, which point to the locations to where DataTables has stored the new rows. So you can do something like:

    [code]
    var aiRow = oTable.fnAddData([...]);
    var nRow = oTable.fnSettings().aoData[ aiRow[0] ].nTr;
    [/code]
    To get the TR row that was just added. A loop would of course be needed if you add more than one row.

    Regards,
    Allan
This discussion has been closed.