The sticky headers are not aligning properly with the rest of the table causing the columns to be out of alignment. The issue is that the width of the columns is not being calculated properly which causing the bad alignment. This obviously could be caused by the theme we are using, but considering tableheader.js is a 'core' javascript file, it should work for all themes. Using jQuery's outerWidth() method fixes this and should work universally for all themes.

Attached are two images 'bad' and 'good' to show what this looks like.

Patch to follow

Comments

travist’s picture

Version: 6.x-dev » 7.x-dev
Status: Active » Needs review
StatusFileSize
new1.13 KB
new586 bytes

Here are the patches to fix this issue. Apparently the issue is also in 7.x, so marking this for both 6 and 7.

pverrier’s picture

With the (D7) patch the sticky header reaches now the full width of my tables, this is really better.
The columns are well sized on Firefox, but alas not on IE, Safari PC, Chrome.

travist’s picture

Are you saying that with this patch the columns are still not sized appropriately on IE, Safari PC, and Chrome, or was that were the issue was BEFORE you applied this patch?

travist’s picture

And the patch for 6.x does apply... it is just because it is trying to apply it to 7.x branch since this issue queue was created for 7.x.

pverrier’s picture

StatusFileSize
new146.66 KB

As you can see on the joined screenshots, though the patch improves the rendering, there are still problems with Chrome (or Safari PC).

These renderings are done on a test site using the default bartik theme, on which I modified the style.css :

tr td,
tr th {
  padding: 1%; /* previously: 4px 9px */

This has been done to reproduce the error I've noticed on the website I'm working on, which uses a responsive, customized, theme, where sizes are often given using percents.

In conclusion, the (D7) patch works perfectly for Firefox and corrects huge sizing errors.
For IE, it's almost perfect (on the site I'm working on there are still little shifts of 1 or 2 pixels, but the total width is ok ; it may be due to the combination of other CSS instructions).
The worst is for Chrome or Safari (total width is also good).

travist’s picture

This could be fixed to instead use $that.outerWidth(true) which should include margins and padding in its calculation.

Here is the 7.x patch with this change.

pverrier’s picture

Sorry, it doesn't change anything.

parthipanramesh’s picture

Issue summary: View changes
Status: Needs review » Needs work
malcomio’s picture

Status: Needs work » Needs review

The patch in #2097081-6: Sticky headers are not calculating the column widths properly. works for us on a 7.24 site using a Zen sub-theme - still need to do full cross browser testing though.

csevb10’s picture

We have a custom theme built off of omega 4.x.
Applying this patch resolved column spacing issues in the following browsers on mac osx 10.9.3:

  • Firefox (originally was miscalculating very badly causing the sticky header to be approx 75% of the table)
  • Chrome (minor column width issues)
  • Safari (same as Chrome)
mfb’s picture

Thanks for this, resolved our issues as well.

flocondetoile’s picture

Status: Needs review » Reviewed & tested by the community

Patch #6 solved issue on Drupal 7.34.
Works fine.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 6: 2097081-fix-sticky-header-column-width-7.x-6.patch, failed testing.

Status: Needs work » Needs review
David_Rothstein’s picture

Status: Needs review » Reviewed & tested by the community

Looks like a testbot fluke.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 6: 2097081-fix-sticky-header-column-width-7.x-6.patch, failed testing.

candelas’s picture

Patch #6 solved issue on Drupal 7.34.
Works fine. Thanks @travist

David_Rothstein’s picture

Status: Needs work » Reviewed & tested by the community

Testbot fluke.

candelas’s picture

I hope it passes test soon because each time I update Drupal I have to apply it on each site...

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 6: 2097081-fix-sticky-header-column-width-7.x-6.patch, failed testing.

David_Rothstein’s picture

Version: 7.x-dev » 8.0.x-dev
Issue tags: +Needs backport to D7

I took a closer look at this and essentially the same code appears to be in Drupal 8 - so wouldn't the bug exist there too?

droplet’s picture

D8 using jQuery 2.x which is take care of box-sizing.

andrej galuf’s picture

Confirming #6 worked in 7.38, temporarily overwriting the file in theme until the problem is fixed in core.

vengador’s picture

Confirmed #6 worked for me too! Thanks @travist!

mfb’s picture

Version: 8.0.x-dev » 7.x-dev
Status: Needs work » Needs review

Drupal 8 doesn't have this problem in my testing (it looks like the width calculation issue was fixed in jQuery 1.8) so I'm setting this back to 7.x-dev

digitalfrontiersmedia’s picture

I think there may be some confusion over whether or not travist's patch works depending on how the theme is setting the box-sizing CSS property. I noticed while using the Shiny theme from Drupal Commerce Kickstart 2 that it didn't matter what version of jQuery or which of the above patches etc. were attempted--all proposed solutions had a misaligned sticky table header on my Permissions admin page.

I noticed that Shiny set the table.sticky-header th CSS for box-sizing to "initial". Adding a custom module allows you to introduce CSS that works across themes. Adding the following CSS with a custom module fixed the misaligned sticky headers for me in conjunction with patch #6 above (although it may have fixed it without the patch but I didn't check). I'm assuming this is because the calculations (even $that.outerWidth()) were being calculated wrong because the basis of the calculation was incorrect with the different box-sizing setting.

table.sticky-header th
{
  box-sizing:  border-box !important;
}

Unfortunately, if a theme overrides this setting I'm not sure there's a lot Core could do to foolproof it without starting to get stupidly complex or verbose.

ann b’s picture

Status: Needs review » Needs work

The patch fixed my view perfectly, but the /admin/content page sticky headers became misaligned. We use the Administration Views module, and the Seven theme for administration views. I reversed the patch and then checked to see how Administration Views got the sticky headers to work. It turns out box-sizing is set to content-box on the th elements. I don't know where this got set originally. So I added the following css for my view:

table.sticky-header th
{
  box-sizing:  content-box;
}

And then my view started working. My site uses an omega theme, and box-sizing is set to border-box by default.

Thanks @travist and @DigitalFrontiersMedia.

liam morland’s picture

joseph.olstad’s picture

If you are ajax replacing the table
have a look at this patch and explanation (example):
#1764912-38: Fix regressions and further improve tableheader.js

hughworm’s picture

Came across this using seven as admin theme. #6 didn't work but replacing "width" with "min-width" did (plus I added "box-sizing: border-box" because it needed it and I couldn't think of a reason not to...)
See patch attached.

hughworm’s picture

But there's still a problem: I use module filter to filter the list. After filtering the "normal" header widths change but the sticky ones don't. A workaround is to change the window size while sticky headers are showing. I suppose this is more a problem for module filter than sticky headers.

albertski’s picture

Status: Needs work » Reviewed & tested by the community

I verified that #32 fixes the issue. I tested the patch from #32 in Safari, IE11, Edge, Chrome, and Firefix and verified it fixes the issue.

poker10’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -Needs backport to D7 +Needs steps to reproduce, +Needs manual testing

Thanks for working on this. I tried to simulate the issue, but with no luck. On a clean D7 install using the Seven admin theme (and some random content generated by Devel module), the sticky header on the table on admin/content is aligned correctly even without the patch (tested on Firefox and Chrome).

Can we get an update, if this is still an issue? If yes, please update the issue summary with steps to reproduce the issue. Automated tests does not help us here, so we need to manually reproduce and test this. Thanks!

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.