How do I make bootstrap table rows clickable? [duplicate]
I can hack this myself, but I think bootstrap has this capability.
Solution 1:
Using jQuery it's quite trivial. v2.0 uses the table
class on all tables.
$('.table > tbody > tr').click(function() {
// row was clicked
});
Solution 2:
There is a javascript plugin that adds this feature to bootstrap.
When rowlink.js
is included you can do:
<table data-link="row">
<tr><td><a href="foo.html">Foo</a></td><td>This is Foo</td></tr>
<tr><td><a href="bar.html">Bar</a></td><td>Bar is good</td></tr>
</table>
The table will be converted so that the whole row can be clicked instead of only the first column.
Solution 3:
That code transforms any bootstrap table row that has data-href
attribute set into a clickable element
Note: data-href
attribute is a valid tr
attribute (HTML5), href
attributes on tr element are not.
$(function(){
$('.table tr[data-href]').each(function(){
$(this).css('cursor','pointer').hover(
function(){
$(this).addClass('active');
},
function(){
$(this).removeClass('active');
}).click( function(){
document.location = $(this).attr('data-href');
}
);
});
});