Determining if a row exists

Determining if a row exists

rcritenrcriten Posts: 5Questions: 0Answers: 0
edited October 2009 in General
Sorry if this is a trivial question, but I've been beating my head for several hours with no luck: Basically, I am creating table via AJAX calls. I can see the data and, when filtering is off, everything works as expected. However, when the user starts to filter the data, I get duplicate records for each entry not in the view. I attempted to use myTable.fnGetNodes() which shows me all the nodes in the table and, using firebug, their visual status. My trouble is in using a selector on the node list to check if a datapoint is new or an update to an existing entry.

>>> var nodes = vmTable.fnGetNodes();
>>> nodes
[tr#0.odd, tr#1.even, tr#2.odd, tr#3.even, tr#4.odd, tr#5.even, tr#6.odd, tr#7.even, tr#8.odd, tr#9.even, tr#10.odd, tr#11.even, tr#12.odd]

/// this is showing me that get nodes is returning the correct rows in the table. The ones not rendered are greyed out /// which isn't shown here.

What I'd like to do is something on the order of:

$(nodes).find('tr#0') which would return valid

or

$(nodes).find('tr#42') which would indicate that the id was for a new record.

Any suggestions would be greatly appreciated.

Thank you in advance

Replies

  • allanallan Posts: 61,723Questions: 1Answers: 10,108 Site admin
    Hi rcriten,

    From the jQuery documentation for $.find():

    > This does not search the selected elements, only their descendants. To choose a subset of the elements in the jQuery object, use filter instead. - http://docs.jquery.com/Traversing/find#expr

    So perhaps $.filter() is the way to go? http://docs.jquery.com/Traversing/filter

    Another option would be to do something like $('tr#0', nodes).length == 1 (if true then you have the target node, otherwise you don't).

    Possibly one for the jQuery e-mail lists though... :-)

    Regards,
    Allan
  • rcritenrcriten Posts: 5Questions: 0Answers: 0
    Allan;

    Thank you for the quick response. The filter() function was the way to go for me.

    Here is what

    var nodes = vmTable.fnGetNodes();
    if( $(nodes).filter('tr#' + uuid).length == 1 ) {
    .... do something ....
    }

    Your pointers were a big help. Thanks again.
This discussion has been closed.