Get the value of a dataTables cell

Get the value of a dataTables cell

annstimmelannstimmel Posts: 2Questions: 0Answers: 0
edited February 2012 in General
Hi, all. Apologies if this has been addressed before, but I think I searched through everything without finding a similar question. I've got an array of values that I'm iterating through, looking for matches in my dataTable. To get the values I want from a plain html table, I'd do this:

[code]
$.each(myArray, function(i, v){
$("#myTable tr td:contains("+v+")").each(function(){
alert($(this).text());
})
})
[/code]

The big picture, in cause it might help, is this: myArray is populated based on user interaction with a graph, the values in myArray are used to get row indices from myTable, which are then used to return the values from another column (the above snippet is a test that returns the values from myTable that match those in myArray). I've tried working with fnGetData, but I'm not sure if that's the right approach or, if it is, how I can feed it a node without a table click event.

Any help would be greatly appreciated!!

Replies

  • annstimmelannstimmel Posts: 2Questions: 0Answers: 0
    This ended up being a problem with the graph reference, not with the dataTables plugin. The above code DOES work.
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Sounds like this would be an ideal case for the underscore function (_):

    [code]
    datatable._('td:contains('+v+')')
    [/code]

    _ will give you an array of data from what is found based on the jQuery selector - i.e. the selector should pick TR or TD/TH cells from the table and you'll get the data from the cells selected back. If you wanted the cells you could use the $ API method.

    Allan
This discussion has been closed.