I can hack this myself, but I think bootstrap has this capability.
Using jQuery it's quite trivial. v2.0 uses the table
class on all tables.
$('.table > tbody > tr').click(function() {
// row was clicked
});
$('#my_id > tbody > tr')
stefita 2015-05-26 23:32
.on('click', function(){});
instead of .click
mauricehofman 2015-10-14 17:13
.on(click, handler).
And to be honest, when i typed that comment, i thought .click was deprecated. But i got that mixed up with .live()
- mauricehofman 2016-03-30 10:10
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.
bootstrap.css
and jasny-bootstrap.css
and load jasny-bootstrap.js
. For the use of rowlink see http://jasny.github.io/bootstrap/javascript/#rowlin - Jasny - Arnold Daniels 2014-02-16 01:00
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');
}
);
});
});
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>
<tr height="70" onclick="location.href='<%=site_adres2 & urun_adres%>'"
style="cursor:pointer;">
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
}
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");