Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Datatables - Make whole row a link

Tags:

This maybe simple, but cant seem to figure it out. Using jquery datatables how can I make each row clickable to just link to a normal page? So if someone moused over any of the row the whole row will hightlight and be clickable and link to whatever url I would want it to link to when clicked.

like image 444
John Avatar asked Sep 22 '11 23:09

John


2 Answers

I've use the fnDrawCallback parameter of the jQuery Datatables plugin to make it work. Here is my solution :

fnDrawCallback: function () {    $('#datatable tbody tr').click(function () {      // get position of the selected row     var position = table.fnGetPosition(this)      // value of the first column (can be hidden)     var id = table.fnGetData(position)[0]      // redirect     document.location.href = '?q=node/6?id=' + id   })  } 

Hope this will help.

like image 132
Preview Avatar answered Sep 18 '22 20:09

Preview


This did it for me using the row callback.

fnRowCallback: function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {     responsiveHelper.createExpandIcon(nRow);     $(nRow).click(function() {         document.location.href = 'www.google.com';     }); }, 
like image 20
andialles Avatar answered Sep 20 '22 20:09

andialles