Problem
When using the sScrollX
, sScrollXInner
and/or sScrollY
to achieve a fixed header table with its inner content scrolling, the headers of the table go out of alignment with the rest of the body in Chrome and IE. Firefox, on the other hand, displays them perfectly.
Using the version 1.9.4, as far as I can tell, this issue only occurs when there is a lot of data with fluctuating widths, and with words that are very long/unwrappable combined in the same columns as small ones. Also, the table in question needs to be fairly wide.
All these factors are demonstrated in this fiddle:
Output
Suggested Solutions
These solutions have been suggested before but have had no effect on my implementation. Owing to some of these suggestions, I setup a clean plain vanilla demo as I wanted to ensure that no other code was contributing to this effect.
- turn-off/remove all my css
setTimeout( function () { oTable.fnAdjustColumnSizing(); }, 10 );
- calling
oTable.fnFilter( "x",0 )
andoTable.fnFilter( "",0 )
in that order "sScrollXInner": "100%"
- get rid of all widths
The only solution that I found to the misaligned headers was taking out sScrollX
and sScrollY
, but this can't be counted as a solution as you lose the fixed header/inner content scrolling functionality. So sadly it's a temporary hack, not a fix!
Note
To edit/play with the latest fiddle.
I have tried various combinations which can be observed in the revision history of the fiddle by using the link http://jsfiddle.net/pratik136/etL73/#REV#
where 1 <= #REV# <= 12
History
StackO
This question has been asked before: jQuery Datatables Header Misaligned With Vertical Scrolling
but the vital difference is that the OP of that question mentioned that they were able to fix the issue if all CSS was removed, which is untrue in my case, and I have tried a few permutations, thus thought the question worthy of a repost.
External
This issue has also been flagged on the DataTables forum:
- http://datatables.net/forums/discussion/7395/sscrolly-and-sscrollx-broken/p1
- http://datatables.net/forums/discussion/7778/vertical-scrolling-messes-up-column-header-alignment#Item_1
- http://datatables.net/forums/discussion/3835/width-columns-problem-in-chrome-safari/p1
- My bug report: http://datatables.net/forums/discussion/12491/datatables-header-alignment-issue-refresh#Item_1
This issue has driven me nuts! Please contribute your thoughts!
See Question&Answers more detail:os