Scroll table (but not thead)
I have a (long) Bootstrap table that I want to allow scrolling with overflow: auto;
. I want it to tbody
be scrollable, not thead
content.
Please see this fiddle for my attempt. I tried to set the height to tbody
unsuccessful.
source to share
You cannot set the tbody to be scrollable. You need to create two separate tables, one for the header and one for the body. Wrap the body table in a div and set the overflow-y property to scroll.
Updated jsfiddle: http://jsfiddle.net/SzGW3/37/
Markup:
<div class="scrollable">
<table class="table table-hover table-striped">
<thead>
<tr>
<th>User</th>
<th>Rights</th>
<th></th>
</tr>
</thead>
</table>
</div>
<div class="bodycontainer scrollable">
<table class="table table-hover table">
<tbody id="user-rows">
<tr class="user-row" style="opacity: 1;">
<td>Justin</td>
<td>Administrator</td>
<td><span class="btn btn-mini btn-primary edit pull-right fade">Edit</span>
</td>
</tr>
<tr class="user-row" style="opacity: 1;">
<td>Sebastien</td>
<td>Administrator</td>
<td><span class="btn btn-mini btn-primary edit pull-right fade">Edit</span>
</td>
</tr>
<tr class="user-row" style="opacity: 1;">
<td>Steve</td>
<td>Operator</td>
<td><span class="btn btn-mini btn-primary edit pull-right fade">Edit</span>
</td>
</tr>
<tr class="user-row" style="opacity: 1;">
<td>Thomas</td>
<td>Administrator</td>
<td><span class="btn btn-mini btn-primary edit pull-right fade">Edit</span>
</td>
</tr>
<tr class="user-row" style="opacity: 1;">
<td>admin</td>
<td>Administrator</td>
<td><span class="btn btn-mini btn-primary edit pull-right fade">Edit</span>
</td>
</tr>
</tbody>
</table>
</div>
Style:
@import url('http://twitter.github.com/bootstrap/assets/css/bootstrap.css');
.scrollable {
overflow-y: scroll;
}
.bodycontainer {
height: 100px !important;
width: 100%;
}
The scrollbar in the title is designed to keep the width the same. You can fix this with some kind of JavaScript, but there should also be some interesting JS / JQuery libraries you can find to handle the whole text scrolling problem for you.
If you want to set the same width for headers cols (th) and cols (td):
table thead>tr>th{
width: 20% !important; /* 20% for 5, 25% for 4, etc */
}
table tbody>tr>td{
width: 20% !important; /* 20% for 5, 25% for 4, etc */
}
source to share
This might be helpful in your case:
http://www.novasoftware.com/download/jquery_fixedtable/jquery_fixedtable.aspx
Also I will try on fiddle , this might give you a hint:
One row and column and an inner overflow element: auto and fixed height and another table inside:
<tbody id="user-rows">
<tr>
<td>
<div style="overflow:auto; height:10em; width:20em;">
<table >
<tr>
.
.
.
</tr>
</table>
source to share