@@ -20,7 +20,8 @@ import {
2020 SimpleChanges ,
2121 TemplateRef ,
2222 ViewChild ,
23- forwardRef
23+ forwardRef ,
24+ signal
2425} from '@angular/core' ;
2526import { Observable , from } from 'rxjs' ;
2627import { finalize , skip , take , takeUntil } from 'rxjs/operators' ;
@@ -44,6 +45,7 @@ import { GanttMainComponent } from './components/main/gantt-main.component';
4445import { GanttScrollbarComponent } from './components/scrollbar/scrollbar.component' ;
4546import { GanttTableBodyComponent } from './components/table/body/gantt-table-body.component' ;
4647import { GanttTableHeaderComponent } from './components/table/header/gantt-table-header.component' ;
48+ import { GanttSyncScrollXDirective , GanttSyncScrollYDirective } from './directives/sync-scroll.directive' ;
4749import { GANTT_ABSTRACT_TOKEN } from './gantt-abstract' ;
4850import { GANTT_UPPER_TOKEN , GanttUpper } from './gantt-upper' ;
4951import { GANTT_GLOBAL_CONFIG , GanttGlobalConfig } from './gantt.config' ;
@@ -52,7 +54,6 @@ import { NgxGanttTableColumnComponent } from './table/gantt-column.component';
5254import { NgxGanttTableComponent } from './table/gantt-table.component' ;
5355import { GanttDate } from './utils/date' ;
5456import { Dictionary , keyBy , recursiveItems , uniqBy } from './utils/helpers' ;
55- import { GanttSyncScrollXDirective , GanttSyncScrollYDirective } from './directives/sync-scroll.directive' ;
5657
5758@Component ( {
5859 selector : 'ngx-gantt' ,
@@ -141,6 +142,10 @@ export class NgxGanttComponent extends GanttUpper implements OnInit, OnChanges,
141142
142143 @ViewChild ( 'ganttTableBody' , { static : true } ) ganttTableBody : ElementRef < HTMLDivElement > ;
143144
145+ public tableScrollWidth = signal < number > ( 0 ) ;
146+
147+ private resizeObserver : ResizeObserver ;
148+
144149 get loading ( ) {
145150 return this . _loading ;
146151 }
@@ -229,6 +234,7 @@ export class NgxGanttComponent extends GanttUpper implements OnInit, OnChanges,
229234 this . computeTempDataRefs ( ) ;
230235 } ) ;
231236 }
237+ this . initScrollContainerObserver ( ) ;
232238 }
233239
234240 ngAfterViewChecked ( ) {
@@ -413,4 +419,27 @@ export class NgxGanttComponent extends GanttUpper implements OnInit, OnChanges,
413419 this . table . dragEnded . emit ( event ) ;
414420 this . draggingItem = null ;
415421 }
422+
423+ private initScrollContainerObserver ( ) {
424+ if ( this . ganttTableBody && this . ganttTableBody [ 'elementRef' ] ?. nativeElement ) {
425+ this . tableScrollWidth . set ( this . ganttTableBody [ 'elementRef' ] . nativeElement . clientWidth ) ;
426+ if ( typeof ResizeObserver !== 'undefined' ) {
427+ this . resizeObserver = new ResizeObserver ( ( entries ) => {
428+ const newWidth = entries [ 0 ] . target . clientWidth ;
429+ if ( this . tableScrollWidth ( ) !== newWidth ) {
430+ this . tableScrollWidth . set ( newWidth ) ;
431+ this . cdr . markForCheck ( ) ;
432+ }
433+ } ) ;
434+ this . resizeObserver . observe ( this . ganttTableBody [ 'elementRef' ] . nativeElement ) ;
435+ }
436+ }
437+ }
438+
439+ override ngOnDestroy ( ) {
440+ super . ngOnDestroy ( ) ;
441+ if ( this . resizeObserver ) {
442+ this . resizeObserver . disconnect ( ) ;
443+ }
444+ }
416445}
0 commit comments