How do I make bootstrap table rows clickable?

CssHtmlTwitter Bootstrap

Css Problem Overview


I can hack this myself, but I think bootstrap has this capability.

Css Solutions


Solution 1 - Css

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 - Css

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 - Css

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'); 
			}
		);
	});
});

Solution 4 - Css

I show you my example with modal windows...you create your modal and give it an id then In your table you have tr section, just ad the first line you see below (don't forget to set the on the first row like this

<tr onclick="input" data-toggle="modal" href="#the name for my modal windows" >
 <td><label>Some value here</label></td>
</tr>																							    																					

																							           
																							   

Solution 5 - Css

<tr height="70" onclick="location.href='<%=site_adres2 & urun_adres%>'"
    style="cursor:pointer;">

Solution 6 - Css

May be you are trying to attach a function when table rows are clicked.

var table = document.getElementById("tableId");
var rows = table.getElementsByTagName("tr");
for (i = 0; i < rows.length; i++) {
    rows[i].onclick = functioname(); //call the function like this
}

Solution 7 - Css

You can use in this way using bootstrap css. Just remove the active class if already assinged to any row and reassign to the current row.

    $(".table tr").each(function () {
        $(this).attr("class", "");
    });
    $(this).attr("class", "active");

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionrjurneyView Question on Stackoverflow
Solution 1 - CssTerryView Answer on Stackoverflow
Solution 2 - CssArnold DanielsView Answer on Stackoverflow
Solution 3 - CssSimmonizView Answer on Stackoverflow
Solution 4 - CssmatouuuuuView Answer on Stackoverflow
Solution 5 - CssalpcView Answer on Stackoverflow
Solution 6 - CssStarxView Answer on Stackoverflow
Solution 7 - CssNarenView Answer on Stackoverflow