Row click event -- need to work with one of the cell content of the clicked row
Row click event -- need to work with one of the cell content of the clicked row
satya_v
Posts: 3Questions: 0Answers: 0
Hey friends,
Currently we are implementing the jquery data table 1.8.*
we are able to reach the row click event, still we are facing problem with accessing the one content of a cell
can some body advice me for the resolution
Thanks,
Satya.
Currently we are implementing the jquery data table 1.8.*
we are able to reach the row click event, still we are facing problem with accessing the one content of a cell
can some body advice me for the resolution
Thanks,
Satya.
This discussion has been closed.
Replies
I don't know if this is what you need but maybe it will help.
I have users selecting rows and the value of the first column is added/removed from an array. It is the aData[1] that specifies the value in the first column.
oTable = $('#contactList').dataTable({
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
// user selected rows
if ( jQuery.inArray(parseInt( aData[1] ), gaiSelected) != -1 ){
$(nRow).addClass('row_selected');
}
return nRow;
}
});
$('#contactList tbody tr').live('click', function () {
var aData = oTable.fnGetData( this );
var iId = aData[1];
iId = parseInt(iId,10);
if ( jQuery.inArray(parseInt(iId), gaiSelected) == -1 ){
gaiSelected[gaiSelected.length++] = parseInt(iId,10);
$(this).addClass('row_selected');
}else{
gaiSelected = jQuery.grep(gaiSelected, function(value) {
return value != iId;
});
if ( $(this).hasClass('row_selected') ){
$(this).removeClass('row_selected');
}
}
});
I found most of this solution in other posts on this forum.
Allan
It might be easier to do something like this though:
[code]
$('#contactList').dataTable({
fnRowCallback: function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
// Row click
$(nRow).on('click', function() {
console.log('Row Clicked. Look I have access to all params, thank You closures.', this, aData, iDisplayIndex, iDisplayIndexFull);
});
// Cell click
$('td', nRow).on('click', function() {
console.log('Col Clicked.', this, aData, iDisplayIndex, iDisplayIndexFull);
});
}
});
[/code]