I have table
that renders inside a panel
which is inside a modal
. As the table is relatively large, I'd like to restrict it's rows to say 5 so that the modal does not become scrollable. I looked through SO and google and everywhere I see that I need to set the overflow-y:auto
or overflow-y:scroll
to get it to work, however in my case, it does not. I also set a random height of 400px and position:absolute. This got the table to be scrollable but now the panel closes with the <thead>
and the body of the table renders outside the panel. What's the fix to this?
My code snippet is:
<div class="modal fade">
<div class="modal-dialog " >
<div class="modal-content">
<div class="modal-body">
<div class="panel panel-default">
<div class="panel-body">
<table class="table table-bordered>
<thead>
[........]
</thead>
<tbody style="overflow-y:auto; height:400px; position:absolute>
[.......]
</tbody>
</table>
[...the rest of the </div>
s...]
Thanks for the responses. Is there a way to narrow down the scroll bar to the <tbody>
alone so that the <thead>
remains static?
Instead put style on the div with class panel-body as overflow-y:scroll; height:200px; see demo below in answers. Do you have a missing end quote on the table class in your source too, or is that just an artifact from cutting down the code here in the question.
Here is the task to make vertically scrollable in a bootstrap row. It can be done by the following approach: Approach: Making all the div element in next line using position: absolute; property (arrange all div column-wise).
Suppose we want to add a scroll bar option in HTML, use an “overflow” option and set it as auto-enabled for adding both horizontal and vertical scroll bars. If we want to add a vertical bar option in Html, add the line “overflow-y” in the files.
Wrap it in table-responsive
and set a max-height:
.table-responsive {
max-height:300px;
}
http://www.codeply.com/go/S6MgKWqFvj
Here is the demo
#collapse1{
overflow-y:scroll;
height:200px;
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="container">
<h2>Collapsible List with table</h2>
<div class="panel-group">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" href="#collapse1">Collapsible list group with table</a>
</h4>
</div>
<div id="collapse1" class="panel-collapse collapse">
<table class="table">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody >
<tr>
<td>John</td>
<td>Doe</td>
<td>[email protected]</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>[email protected]</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>[email protected]</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>[email protected]</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>[email protected]</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>[email protected]</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>[email protected]</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>[email protected]</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>[email protected]</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With