5

I have developed a table in bootstrap using the "table-responsive" class and it works as expected, however as the table is rather large and will be used on a range of devices I need to make it more user friendly. I have searched the forums but cannot find what I am after.

Is it possible to have the scrollbar which appears at the bottom of responsive table visible at all times and not just when the screen is minimized to a certain extent?

Also is there any way to replicate this scrollbar at the top of the table as well? As the table will be long it would be a better solution to have it visible at the top and bottom.

Antoin McCloskey
  • 121
  • 1
  • 2
  • 9

3 Answers3

8

For a horizontal scrollbar on top try using the jquery.doubleScroll plugin

jQuery:

$(document).ready(function(){
  $('.table-responsive').doubleScroll();
});
nodws
  • 1,018
  • 14
  • 18
3

If i get you right. Make the container which the table is in have a fixed with and height, also have the overflow property set to auto. By doing that you table can't be 100% because it will fill its container. That means the table as to have a fixed width also which is larger than it's container to show the overflow effect. See sample below. i hope it helps or point you to the right direction

.table-cont {
    max-width: 400px;
    max-height: 200px;
    overflow: auto;
    border: 1px red solid;
 }
 .table-cont .table {
    min-width: 600px;
 }
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <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/3.2.0/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <div class="table-cont">
  <table class="table">
    <thead>
      <tr>
        <th>Firstname</th>
        <th>Lastname</th>
        <th>Email</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Default</td>
        <td>Defaultson</td>
        <td>def@somemail.com</td>
      </tr>      
      <tr class="success">
        <td>Success</td>
        <td>Doe</td>
        <td>john@example.com</td>
      </tr>
      <tr class="danger">
        <td>Danger</td>
        <td>Moe</td>
        <td>mary@example.com</td>
      </tr>
      <tr class="info">
        <td>Info</td>
        <td>Dooley</td>
        <td>july@example.com</td>
      </tr>
      <tr class="warning">
        <td>Warning</td>
        <td>Refs</td>
        <td>bo@example.com</td>
      </tr>
      <tr class="active">
        <td>Active</td>
        <td>Activeson</td>
        <td>act@example.com</td>
      </tr>
    </tbody>
  </table>
  </div>
</div>

</body>
</html>
blecaf
  • 1,625
  • 1
  • 8
  • 13
0

and here you go

<div class="table-responsive">
 <table class=""table table-striped table-bordered">
  <!--Rest of the code-->

 </table>


 </div>
this.girish
  • 1,296
  • 14
  • 17
  • put your table inside the div tag give it class "table-responsive" to make it responsive on all the devices – this.girish Apr 27 '17 at 14:35
  • 1
    According to the question this as been used – blecaf Apr 27 '17 at 14:36
  • @blecaf I figure he is suggesting to use it in a parent div, and not directly at the table as it is usually used. – Leon Freire Apr 27 '17 at 14:37
  • check your code you might give "table-responsive" class to your table tag, put you table inside the div tag give it a class "table-responsive" to achieve what your asking – this.girish Apr 27 '17 at 14:38
  • exactly @LeonFreire that's what i want to tell him – this.girish Apr 27 '17 at 14:45
  • Thanks for your replies. My solution contains a table within the div tag table responsive. It does work as expected and the table will respond when minimized however it is a requirement of user to have the scrollbar at the top and bottom for usability purposes as well as being always visible. – Antoin McCloskey Apr 27 '17 at 14:46
  • share your code or fiddle it, so that we can look into it – this.girish Apr 27 '17 at 14:57
  • http://stackoverflow.com/questions/3934271/horizontal-scrollbar-on-top-and-bottom-of-table?rq=1 this link might help you, go through it – this.girish Apr 27 '17 at 14:59