views:

24

answers:

1

I'm sure this is an easy problem to solve, but I'm just not much of a html/css wizard yet!

I have a table that I generate and the spec calls for there being a fixed header while allowing the body to be scrollable.

The problem is, now the horizontal direction is scrollable also, which I don't want it to be. There is no reason it can't be fixed. It looks like the presence of the scroll bar for the vertical direction takes up space so that the browser now thinks that it needs a horizontal scroll to fit in the horizontal content. Frustrating!

Here is what I have so far:

<table cellspacing="0" cellpadding="4" border="1" bordercolor="cccccc">
        <thead style="position:relative;">
            <tr bgcolor="eeeeee">
                <td>Column 1 Header</td>
                <td>Column 2 Header</td>
            </tr>
        </thead>
        <tbody style="overflow-y:auto;overflow-x:hidden;height:480px;">
            <tr>
                <td>Some data</td>
                <td>Some more data</td>
            </tr>
            <tr>
                <td>Some data</td>
                <td>Some more data</td>
            </tr>
            <tr>
                <td>Some data</td>
                <td>Some more data</td>
            </tr>
            <tr>
                <td>Some data</td>
                <td>Some more data</td>
            </tr>
         </tbody>
      </table>
+1  A: 

Tau, Check out www.datatables.net. It's a Jquery plugin that reformats your tables via JS and allows for sorting, paging, etc. The header "freeze" is exactly the functionality that would solve your problems, and the extra features are just bonus. I've stopped using the "freeze" method and switched nearly entirely to paged tables, which are just a single line of configuration to enable. Personally, I don't deploy tabular data without it anymore, and the extra 5 lines of code only takes me a minute or two to add. It's a win-win in my book, no crazy CSS or reformatting required.

bpeterson76
While that looks like a great solution, is there a way I can accomplish what I'm trying to without resorting to this?
tau-neutrino
Could we see the container div, etc? I suspect that is what's causing the horizontal scrolling. Having done this before, I can tell you it's frustrating because of browser variances and IE's box model issues. Datatables bypasses all of that. And, from a UI standpoint, paging trumps scrolling on long tables such as yours.
bpeterson76
There's no surrounding div etc. I just pulled it up in a different browser and there was no scrolling whatsoever in either direction, so I'm going to go ahead and check your solution as the one to go with.
tau-neutrino