When scrolling through long tables, it is hard to know which column is what. This patch remedies this by letting the table header scroll along when it reaches the top of the browser view. Multiple tables per page are supported (the header will disappear if you scroll beyond the end of a table).

It uses "position: fixed", so it does not lag behind the scrolling and does not slow down rendering (much). This does mean that it won't work in at least IE6, and maybe IE7. But, I think this feature is too handy to not have, so we could just disable it for IE6 users (their loss). For now, no browser checking is provided so we can test it.

Try it on e.g. the watchdog table. Note that the theme can be adjusted to style the fixed header appropriately:

thead div.sticky-header {
  background: #fff;
  border-bottom: 2px solid #d3e7f4;
}

However, in order to keep the feature usable on all themes, I automatically set a white background in system.css.

Tested on Safari, Firefox and Opera.

Patch is against "cvs up -D "01/23/2007" as HEAD is broken at the moment.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Steven’s picture

FileSize
4.74 KB

Fixed some bugs:

  • Make the first cell as wide as the table (under the rest) to avoid 1-2 pixel gaps.
  • Set z-index to avoid some possible rendering bugs.
  • Deal better with changing window/font size.

Demo at:
http://www.acko.net/garland/?q=tracker

Note that it is not easily possible to make the entire header bigger if one or more cells wrap...

adrian’s picture

Just tested this in firefox. Very subtle, but very useful. I'd imagine this must be a big
usability boon for forms like the permission admin.

Steven’s picture

FileSize
5.14 KB

Bugfix: reflow cells on resize. Due to the weird handling of onresize, there is some unavoidable delay here. Pffft.

Dries’s picture

Looks great. Especially for the permissions screen!

Dries’s picture

I looked at the code now, and it looks good. Clever trick, but hard to say if there is a simpler/shorter way to accomplish this (I'm not yet a jQuery expert, but I'm slowly getting there ;)).

Steven’s picture

The code is pretty lean... most solutions out there use "onscroll" to reposition the elements, and this causes it to lag behind. Because I use position: fixed, I don't need to move the header at all. I just show / hide it.

chx’s picture

If by "HEAD is broken at the moment" you mean the menu patch then please reconsider. It indeed lacks a few visual aids and the navigation block is broken in some edge cases but it is totally useable for development and patches. In other words, you might need to type in a /edit into the location bar instead of clicking on 'edit' but once you land on a page, Drupal works.

Morbus Iff’s picture

Firefox 2.0 on OS X against http://www.acko.net/garland/?q=tracker:

1) Grab your scroll bar and scroll down *quickly* and hold the click. Header doesn't show. Release click, header shows.
2) Grab the scroll bar and scroll up (quickly or not). Header goes all the way up, above the table. Eventually disappears, but pieces at a time (I see the first four columns disappear quickly, then Last post lags behind a beat). Depending on some circumstances, 1) is also repeatable upwards - scroll up quickly, hold the click, header remains shown at the top of the page (above the table). Release click, header disappears.

Mousewheel scrolling worked perfectly, same with page down and arrows.

Morbus Iff’s picture

Patch is missing a single space before "div.stickyPosition =".

Steven’s picture

We can't fix those quick scroll issues... Firefox is simply not firing the onscroll event until you let go or hover for a moment.

Steven’s picture

FileSize
5.27 KB

Ok, according to various sources, IE7 supports position: fixed, so I only disabled this feature for IE6 and below. Patch attached.

Ready to go into core IMO.

Steven’s picture

FileSize
5.15 KB

Fixed indentation (it was a tab, not a missing space).

Dries’s picture

Status: Needs review » Fixed

Good stuff. Thanks, Steven.

Anonymous’s picture

Status: Fixed » Closed (fixed)