Searching column value from class name
Searching column value from class name
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
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
This discussion has been closed.
Replies
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.