@@ -41,21 +41,24 @@ export default class Style {
4141
4242 bindScrollHeader ( ) {
4343 this . _settingHeaderPosition = false ;
44+ this . updateStickyTopPositions ( 0 ) ;
4445
4546 $ . on ( this . bodyScrollable , 'scroll' , ( e ) => {
4647 if ( this . _settingHeaderPosition ) return ;
4748
4849 this . _settingHeaderPosition = true ;
4950
5051 requestAnimationFrame ( ( ) => {
51- const left = - e . target . scrollLeft ;
52+ const scrollLeft = e . target . scrollLeft ;
53+ const left = - scrollLeft ;
5254
5355 $ . style ( this . header , {
5456 transform : `translateX(${ left } px)`
5557 } ) ;
5658 $ . style ( this . footer , {
5759 transform : `translateX(${ left } px)`
5860 } ) ;
61+ this . updateStickyTopPositions ( scrollLeft ) ;
5962 this . _settingHeaderPosition = false ;
6063 if ( this . instance . noData ) {
6164 $ . style ( $ ( '.no-data-message' ) , {
@@ -153,6 +156,8 @@ export default class Style {
153156 this . setupColumnWidth ( ) ;
154157 this . distributeRemainingWidth ( ) ;
155158 this . setColumnStyle ( ) ;
159+ this . setStickyColumnStyle ( ) ;
160+ this . updateStickyTopPositions ( this . bodyScrollable . scrollLeft || 0 ) ;
156161 this . setBodyStyle ( ) ;
157162 }
158163
@@ -310,6 +315,8 @@ export default class Style {
310315 this . columnmanager . setColumnHeaderWidth ( column . colIndex ) ;
311316 this . columnmanager . setColumnWidth ( column . colIndex ) ;
312317 } ) ;
318+ this . setStickyColumnStyle ( ) ;
319+ this . updateStickyTopPositions ( this . bodyScrollable . scrollLeft || 0 ) ;
313320 }
314321
315322 setBodyStyle ( ) {
@@ -371,6 +378,56 @@ export default class Style {
371378 return $ ( `.dt-cell--col-${ colIndex } ` , this . header ) ;
372379 }
373380
381+ setStickyColumnStyle ( ) {
382+ if ( ! this . datamanager || ! this . datamanager . getColumns ) return ;
383+
384+ const stickySelectors = [ ] ;
385+ let stickyOffset = 0 ;
386+ let normalOffset = 0 ;
387+
388+ this . datamanager . getColumns ( ) . forEach ( ( column ) => {
389+ const $headerCell = this . getColumnHeaderElement ( column . colIndex ) ;
390+ const renderedWidth = $headerCell ? $headerCell . offsetWidth : column . width ;
391+
392+ if ( column . sticky ) {
393+ const selector = `.dt-cell--col-${ column . colIndex } .dt-cell--sticky` ;
394+ const style = {
395+ left : `${ stickyOffset } px`
396+ } ;
397+
398+ column . stickyLeft = stickyOffset ;
399+ column . stickyScrollTrigger = normalOffset - stickyOffset ;
400+ column . renderedWidth = renderedWidth ;
401+ this . setStyle ( selector , style ) ;
402+ stickySelectors . push ( selector ) ;
403+ stickyOffset += renderedWidth ;
404+ }
405+ normalOffset += renderedWidth ;
406+ } ) ;
407+
408+ const staleSelectors = ( this . _stickySelectors || [ ] )
409+ . filter ( selector => ! stickySelectors . includes ( selector ) ) ;
410+
411+ staleSelectors . forEach ( selector => this . removeStyle ( selector ) ) ;
412+ this . _stickySelectors = stickySelectors ;
413+ }
414+
415+ updateStickyTopPositions ( scrollLeft ) {
416+ if ( ! this . datamanager || ! this . datamanager . getColumns ) return ;
417+
418+ const stickyColumns = this . datamanager . getColumns ( ) . filter ( column => column . sticky ) ;
419+
420+ stickyColumns . forEach ( ( column ) => {
421+ const trigger = Math . max ( 0 , column . stickyScrollTrigger || 0 ) ;
422+ const compensation = Math . max ( 0 , scrollLeft - trigger ) ;
423+ const cells = $ . each ( `.dt-cell--col-${ column . colIndex } .dt-cell--sticky-top` , this . wrapper ) || [ ] ;
424+
425+ $ . style ( cells , {
426+ transform : compensation ? `translateX(${ compensation } px)` : ''
427+ } ) ;
428+ } ) ;
429+ }
430+
374431 getRowIndexColumnWidth ( ) {
375432 const rowCount = this . datamanager . getRowCount ( ) ;
376433 const padding = 22 ;
0 commit comments