Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 81728

Hyperlink entire row or cell using data-href attribute

$
0
0

I saw the example in the documentation for using a column renderer to make the value in the column a hyperlink. However I wanted to make the entire row or cell a hyperlink, not just the text within it (and not using css display). I was curious how you would go about making a row or column a hyperlink using jquery delegated events and the data-href attribute. I got this working by simply referring to the actual table data with the following:

var rankTable = $('#myTable').DataTable();
$('#myTable').on('click', 'tbody tr', function() {
  window.location.href = `someurl/${table.row(this).data()[1]}`;
});

but i would like to know how to go about adding the data-href attribute to a td or tr if i wanted to be able to do something like the following:

<tr data-href='someurl/1234'>
  <td>Cell Data</td>
</tr>
$('#myTable').on('click', 'tbody tr', function() {
  window.location.href = $(this).data('href');
});

I swore I saw an example somewhere about adding attributes to rows or cells but can't seem to find it now.


Viewing all articles
Browse latest Browse all 81728

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>