Check out the small html structure sample below for context. Check out this fiddle for and example of the problem.
Short explanation for fiddle users:
- Scroll left – vertical scroll bar not visible
- Scroll right – vertical visible
- I want the vertical scroll bar always visible
- Requirement – The header must remain fixed (visible while scrolling)
Long explanation:
I have a table with a fixed header and a scrollable body. The complexities of that requires two tables. That’s all good. In my cause I also have resizable columns. table-layout: fixed for that to work. This is were problems arise.
To make the scrolling body work I’ve got a div that wraps the .rows table for scrolling. This works great until the grid, specifically the .rows table, overflows in the x direction. In this case the the vertical scroll bar is only visible if the grid is scrolled all the way to the right. Because the scroll bar is on the .row-wrapper div. And that overflow is being hidden by the .grid div. I’d like the scrollbar to be on the .grid-canvas div so that it is visible even when scrolled to the left side.
<div class=grid>
<div class=grid-canvas>
<table class=header></table>
<div class=row-wrapper>
<table class=rows></table>
</div>
</div>
</div>
side note: If you set the table display to block then the wrapping div isn’t needed unless you want to support IE8 which I do. Maybe there’s a way around that but that another question for another time.
Well after hours of hacking with no luck I decided to disect some of the existing libraries to see how they were accomplishing this. Unfortunately I was sorely disappointed. All of them were using javascript.
The up side to this is that the it only requires a small bit of code not that that means it will perform well. To make this perform as well as possible I’m updating the header when required in the x direction. Since this will typically be a small area in my case it should be good enough.
Hundredth times a charm!
fiddle
Here’s the basic:
HTML
Javascript
CSS