I have a DataTables Table, and I want to be able to get the value of the first td, when the tr is clicked on. I have set the visibility of this td to false.
Edit: because the two answers so far are assuming I can click on the cell I want. I cannot click on the cell I need the value of.
$(document).ready(function() {
var table = $('#example').DataTable({
select: false,
"columnDefs": [{
className: "ID",
"targets":[0],
"visible": false,
"searchable":false
}]
});//End of create main table
$('#example tbody').on( 'click', 'tr', function () {
cellValue = //code to get the cell value
console.log(cellValue);
});
});
I have seen a lot of examples using the older DataTables method, fnGetColumnData, but am not sure how to implement the newer cell.data().
Can anyone help me out?
To achieve expected result and get hidden column data by using row(this).data()
$('#example tbody').on( 'click', 'tr', function () {
alert(table.row( this ).data()[0]);
});
http://codepen.io/nagasai/pen/kXyazm
Above mentioned code will return complete row data both hidden and visible data and mention the position of the hidden column position