Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a table, which is wider than screen size, scrollable and keep header row fixed?

I've a table with 2 columns and each column is 800px wide. I want to show this table in 800x50 window. So there should be horizontal and vertical scrollbar to view complete table.

While I've found few related solutions (this and this) on SO, they only work if table width is smaller than screen size. In my case screen size is 1200px and total table width is 1600px.

How could I do this? i want to achieve something like this.

EDIT Oops, I forgot to add one more requirement. Sorry. I want the header of the table to remain fixed while user scrolls table.

EDIT2

I've tried below mentioned solutions to wrap in a div, but in this case vertical scrollbar doesn't show up. Please see this table with wrapper div. It seems this problem only occurs if table width is bigger than screen size. I'm testing on FF3.6.

EDIT3

current table code. This has no vertical scroller even though I can scroll vertically.

<div style="overflow:scroll; width:800px;height:50px" >
<table style="width:1600px" border="1">
  <thead>
    <tr>
        <th style="width:800px">id_1</th>
        <th style="width:800px">id_1</th>
    </tr>
  </thead>
  <tbody style="">
    <tr><td>1200</td><td>1200</td></tr>
    <tr><td>1200</td><td>1200</td></tr>
    <tr><td>1200</td><td>1200</td></tr>
    <tr><td>1200</td><td>1200</td></tr>
    <tr><td>1200</td><td>1200</td></tr>
    <tr><td>1200</td><td>1200</td></tr>
  </tbody>
</table>
</div>
like image 294
understack Avatar asked Apr 13 '10 18:04

understack


2 Answers

You could wrap the table in a div that has a fixed-size (800x50) and set overflow:scroll.

like image 73
Vivin Paliath Avatar answered Nov 14 '22 03:11

Vivin Paliath


Put your table in a div with width < 800, and set overflow: scroll.

like image 38
Jeff B Avatar answered Nov 14 '22 03:11

Jeff B