Sticky table headers can fail when one is using a module like admin_menu, and I saw recently a fix in the drupal7 branch to fix a similar problem with the admin toolbar. However, sticky headers also don't work if your table is in a div with overflow:auto set.
My problem is that much of my content is in a div styled with 'overflow: auto', so it has its own scrollbars for long content. On pages like the user permissions page, the table header will scroll outside of view, but it won't know it, so the header disappears, defeating the purpose of sticky headers. If I then re-size the browser window, I can sometimes get the sticky header to reappear at the top of the browser window, although that's not ideal, and even then it still gets obscured by the admin_menu div.
Is there a way to fix this behavior so that the table header knows when it is about to scroll out of view in a general case like this?
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | tableheader-supplement.zip | 1.79 KB | ChevronTango |
| #5 | tableheader-supplement.zip | 1.78 KB | ChevronTango |
| #4 | tableheader-supplement.zip | 1.77 KB | ChevronTango |
Comments
Comment #1
kingandyDid you get anywhere with this? I'm running up against it myself and am about to break open the sticky-headers JS for repurposing...
Comment #2
kingandyI knocked together a quick and dirty jQuery using some nabbed code from tableheader.js. Most of that file seems to be about watching scroll activity so it can make the sticky header visible when the table reaches the top of the page - without that (ie, for a fixed position header) it's quite straightforward.
Here's what I ended up with:
'.scrolly' is obviously my container, use your own identifier to make it work with your theme.
the 'var headerClone' line is what I stole from tableheader.js, though I dropped the 'top: 0px' declaration. Before that, though, I added a step through each of the TH elements in the header to give a firm CSS-declaration to set their 'width' to match their current naturally-derived width. This is purely because my table's cell widths are all set to auto ... it looks like tableheader.js does something similar, but it uses clientWidth instead of width() - this may be to do with borders or padding or Internet Explorer.
I'm experiencing some unusual IE behaviour (as always), but the above may at least give people a starting point...
Comment #3
kingandyChanging 'fixed' to 'absolute' seems to have fixed my IE issues ... and kind of makes sense, I don't want the thing to be fixed when the page scrolls, I just want to to remain absolutely positioned where it is when the current scroll area scrolls.
Comment #4
ChevronTango commentedI came across this same problem on my site and thought I'd have a crack at a solution. Not even knowing if one was possible, this was a bit of trial by fire.
I know very little about JS so this was my first real tackle at it. I've not tested this extensively but I managed to get this working to my liking (at least in firefox). Instead of
I have used my own script
*note the scrollable div now has to have an identifying class aswel
Attached is the contents of that js file. Its virtually identical to the ordinary Sticky Tableheaders JS but I've littered it with minor alterations here and there and kinda lost track of what I have and havent done. Let me know what you guys think.
Comment #5
ChevronTango commentedMy apologises, found a careless bug. The below is fixed.
Comment #6
ChevronTango commented...and another.
Comment #7
rootical commentedUnfotunately it didn`t work for me ;(
Firebug gives the following mistake:
this.originalContainer.offset() is null
It there a way to fix this? Thanks a lot..
Comment #8
catchThis is just a normal bug.
Please provide steps to reproduce, ideally with screenshots.
Comment #9
rootical commentedI`m sorry but maybe my problem is not strictly the same so i created a new issue:
http://drupal.org/node/1429048
Thank you