Searching column value from class name

Searching column value from class name

ZiTouNZiTouN Posts: 6Questions: 0Answers: 0
edited July 2011 in General
Hi,

I would like to know if we can search for a value of a row cell (hidden or not) from the class of the column it belongs to.
Let me give an example to be clearer.
Starting this table datas:
[code]


Id User
User Name
Age


1john99
2elizabeth35
3mickael61


[/code]
We have the following dataTable implementation:
[code]
$("#myTable").dataTable( {
"aoColumnDefs": [ {
"bVisible": false,
"aTargets": ["id_user"]
}
});
[/code]
Then we have this event on the table:
[code]
$('#myTable tbody tr').dblclick(function() {
var oTable = $(this).parents('table').dataTable();
//Trying to get the value of the id_user column clicked to construct an url
//var aData = oTable.fnGetData(this); returns a table with all row values, but without the name of the column
});
[/code]

Thanks in advance for your replies.

Olivier

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    edited July 2011
    Do you mean for a row clicked (or other event) you want to get the value in the id_user column?

    oTable.fnSettings().aoColumns[] keeps a list of your column definitions. sTitle is the value of that column (innerText of the TH column, unless you over-ride this in your intializations)

    [code]
    $('#myTable tbody tr').dblclick(function() {
    for (i = 0; i < oTable.fnSettings().aoColumns.length; i++) {
    if (oTable.fnSettings().aoColumns[i].sTitle == "Id User")
    console.log('the value of Id User for this row is', oTable.fnGetData(this)[i]); // fnGetData(this, i) should work, but didn't
    }
    });
    [/code]

    the value is in oTable.fnGetData(this)[i] where 'this' is the row DOM passed in by JQuery, and i is the number of the column whose sTitle matched your Id column name.
  • ZiTouNZiTouN Posts: 6Questions: 0Answers: 0
    Thanks for you quick reply, I found a similar solution using DOM parsing.
This discussion has been closed.