@@ -23,6 +23,7 @@ export default class Style {
2323 this . styleEl = styleEl ;
2424
2525 this . bindResizeWindow ( ) ;
26+ this . bindScrollHeader ( ) ;
2627 }
2728
2829 get stylesheet ( ) {
@@ -38,6 +39,60 @@ export default class Style {
3839 }
3940 }
4041
42+ bindScrollHeader ( ) {
43+ this . _settingHeaderPosition = false ;
44+
45+ $ . on ( this . bodyScrollable , 'scroll' , ( e ) => {
46+
47+ if ( this . _settingHeaderPosition ) return ;
48+
49+ this . _settingHeaderPosition = true ;
50+
51+ requestAnimationFrame ( ( ) => {
52+
53+ const scrollLeft = e . target . scrollLeft ;
54+
55+ // Move non-sticky header and footer cells normally
56+ const nonStickyHeaderCells = this . header . querySelectorAll ( '.dt-cell:not(.dt-sticky-col)' ) ;
57+ const nonStickyFooterCells = this . footer . querySelectorAll ( '.dt-cell:not(.dt-sticky-col)' ) ;
58+
59+ nonStickyHeaderCells . forEach ( cell => {
60+ $ . style ( cell , { transform : `translateX(${ - scrollLeft } px)` } ) ;
61+ } ) ;
62+
63+ nonStickyFooterCells . forEach ( cell => {
64+ $ . style ( cell , { transform : `translateX(${ - scrollLeft } px)` } ) ;
65+ } ) ;
66+
67+ const stickyHeaderCells = this . header . querySelectorAll (
68+ '.dt-cell.dt-sticky-col:not(.dt-cell-serial-no):not(.dt-cell-checkbox)'
69+ ) ;
70+
71+ stickyHeaderCells . forEach ( ( headerCell ) => {
72+
73+ const colIndex = headerCell . getAttribute ( 'data-col-index' ) ;
74+ const bodyCell = this . bodyScrollable . querySelector ( `.dt-cell[data-col-index="${ colIndex } "]` ) ;
75+ const colLeft = parseFloat ( headerCell . style . left ) || 0 ; // get left position of the column
76+
77+ // Find corresponding footer cell
78+ const footerCell = this . footer . querySelector ( `.dt-cell[data-col-index="${ colIndex } "]` ) ;
79+
80+ if ( ~ ~ ( bodyCell . offsetLeft - scrollLeft ) > colLeft ) {
81+ headerCell . style . transform = `translateX(${ - scrollLeft - 1 } px)` ;
82+ if ( footerCell ) {
83+ footerCell . style . transform = `translateX(${ scrollLeft ? - scrollLeft - 1 : 0 } px)` ;
84+ }
85+ } else {
86+ headerCell . style . transform = `translateX(${ colLeft - headerCell . offsetLeft } px)` ;
87+ if ( footerCell ) footerCell . style . transform = `translateX(${ colLeft - footerCell . offsetLeft } px)` ;
88+ }
89+ } ) ;
90+
91+ this . _settingHeaderPosition = false ;
92+ } ) ;
93+ } ) ;
94+ }
95+
4196 onWindowResize ( ) {
4297 this . distributeRemainingWidth ( ) ;
4398 this . refreshColumnWidth ( ) ;
0 commit comments