Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
16
rated 0 times [  23] [ 7]  / answers: 1 / hits: 43026  / 13 Years ago, wed, november 23, 2011, 12:00:00

I am using datatables in my application. Whenever user click on any row I want to highlight it and pick some values from selected row.



oTableTools: {
sRowSelect: single,

fnRowSelected: function ( node ) {
var s=$(node).children();
alert(Selected Row : + $s[0]);
}


I tried sRowSelect and fnRowSelected but no luck. The row is not highlighted and neither fnRowSelected is called. Even no error on console.



Here is my complete code



  var userTable = $('#users').dataTable({
bPaginate: true,
bScrollCollapse: true,
iDisplayLength: 10,
bFilter: false,
bJQueryUI: true,
sPaginationType: full_numbers,
oLanguage: {
sLengthMenu: Display _MENU_ records per page,
sZeroRecords: Enter a string and click on search,
sInfo: Showing _START_ to _END_ of _TOTAL_ results,
sInfoEmpty: Showing 0 to 0 of 0 results,
sInfoFiltered: (filtered from _MAX_ total results)
},
aaSorting: [[ 0, asc ]],
aoColumns: [/* Name */ null,
/*Institution*/null,
/*Email*/null],
oTableTools: {
sRowSelect: single,

fnRowSelected: function ( node ) {
alert(Clicked);
}
}
});


Am I missing anything ?



EDIT:

Now able to highlight selected row.Added class=display to HTML table. Still wondering why I didn't find this in datatable docs. Now looking how to collect selected values.


More From » jquery

 Answers
9

Here is how I do it



just add this function to your page (if users is your table id)



$(#users tbody).delegate(tr, click, function() {
var iPos = userTable.fnGetPosition( this );
if(iPos!=null){
//couple of example on what can be done with the clicked row...
var aData = userTable.fnGetData( iPos );//get data of the clicked row
var iId = aData[1];//get column data of the row
userTable.fnDeleteRow(iPos);//delete row

}

[#88940] Tuesday, November 22, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
frankiebobbyc

Total Points: 18
Total Questions: 85
Total Answers: 104

Location: Norway
Member since Wed, Jul 7, 2021
3 Years ago
;