recover first column value
recover first column value
ocin35
Posts: 15Questions: 2Answers: 0
hi,
$('#items tbody').on( 'click', 'td', function () {
alert( table.cell( this ).data() );
} );
with this code alert displays the contents of the clicked cell, but how does the first column value get back if you click on any cell in the row?
Please
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Here is one option:
For example:
http://live.datatables.net/hopupepa/1/edit
You may be able to build a more efficient jQuery selector.
Kevin
thank you so much
last question please to display alert only if clicks in column 3?
$('#items tbody').on( 'click', 'td', function () {
i found a solution!!
$('#items tbody').on( 'click', 'td', function () {
if (table.column( $( this )).index() == 1) {
jsID = table.cell( $( this ).closest('tr').find('td:first-child')).data();
alert (jsID);
}
} );
Sorry but the function does not work if column 0 is hidden and works if column 0 is visible - how to do it? please
table.cell( $( this ).closest('tr').find('td:first-child')).data()
See if this does what you want:
http://live.datatables.net/hopupepa/2/edit
Kevin
it does not work
I continue my research, if you have another idea? thank you
I found the solution
the following code shows in alert the value of the hidden column only if the click is done in the first column displayed - thanks
$('#items').on('click', 'td', function (e) {
if (table.column( $( this )).index() == 1) { //first column only
var data1 = table.row( $(this).parents('tr') ).data()["ID"]; //hidden column
alert(data1);
}
} );