id attribute goes missing?

id attribute goes missing?

cmousecmouse Posts: 3Questions: 0Answers: 0
edited November 2012 in Bug reports
I am not sure whether this bug is in Firefox or data tables, but it would appear that any id attributes that tr elements have are removed in pagination. The first 10 elements retain their id or data-id attribute, but on next pages, the attributes appear removed on DOM's perspective. I could not get any IDs out with $("tr")[n].attributes or $("tr")[n].id. I am using jQuery-1.8, jquery-ui-1.9.0 and dataTables-1.9.4.

Replies

  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    Key thing here is that DataTables removes row nodes from the DOM which aren't needed for a page (to help improve speed and compatibility). So you can use `table.$('tr')` to get all table nodes - see http://datatables.net/docs/DataTables/1.9.4/#$

    Allan
  • cmousecmouse Posts: 3Questions: 0Answers: 0
    So when binding listener, should I use table.$('tr').on('click'. ..)?

    Because $('tr').on('click'... doesn't pass in the correct element, as I can't get the id or data-id out with e.target.parentNode.
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    This FAQ is relevant: http://datatables.net/faqs#events

    Sometimes :-). You may want to use table.$().on for static events - but if you are using a live / delegated event, then probably not, and I would recommend the latter method.

    Allan
  • cmousecmouse Posts: 3Questions: 0Answers: 0
    From jQuery API documentation

    [quote]As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers. Users of older versions of jQuery should use .delegate() in preference to .live().[/quote]

    Perhaps it's worth checking that it works with .on() as well?
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    DataTables? Yes it does. All of the examples on this site and the general documentation will be updated soon as part of the 1.10 update :-)

    Allan
This discussion has been closed.