diff --git a/packages/gantt/src/gantt.component.html b/packages/gantt/src/gantt.component.html
index a431e23a..ab876dda 100644
--- a/packages/gantt/src/gantt.component.html
+++ b/packages/gantt/src/gantt.component.html
@@ -2,7 +2,7 @@
@@ -15,7 +15,7 @@
[maxBufferPx]="styles.lineHeight * 20"
>
-
+
,
cdr: ChangeDetectorRef,
ngZone: NgZone,
+ private viewportRuler: ViewportRuler,
@Optional() private printService: GanttPrintService,
@Inject(GANTT_GLOBAL_CONFIG) config: GanttGlobalConfig
) {
@@ -188,7 +177,6 @@ export class NgxGanttComponent extends GanttUpper implements OnInit, OnChanges,
}
ngAfterViewInit() {
- this.updateScrollBarOffset();
if (this.virtualScrollEnabled) {
this.virtualScroll.renderedRangeStream.pipe(takeUntil(this.unsubscribe$)).subscribe((range) => {
const linksElement = this.elementRef.nativeElement.querySelector('.gantt-links-overlay') as HTMLDivElement;
@@ -201,6 +189,18 @@ export class NgxGanttComponent extends GanttUpper implements OnInit, OnChanges,
}
}
+ ngAfterViewChecked() {
+ if (this.virtualScrollEnabled && this.viewportRuler && this.virtualScroll.getRenderedRange().end > 0) {
+ this.ngZone.runOutsideAngular(() => {
+ setTimeout(() => {
+ this.ganttRoot.verticalScrollbarWidth =
+ this.virtualScroll.elementRef.nativeElement.offsetWidth - this.virtualScroll.elementRef.nativeElement.clientWidth;
+ this.cdr.markForCheck();
+ });
+ });
+ }
+ }
+
private buildFlatItems() {
const virtualData = [];
if (this.groups.length) {
@@ -249,16 +249,6 @@ export class NgxGanttComponent extends GanttUpper implements OnInit, OnChanges,
this.viewportItems = [...this.viewportItems];
}
- private updateScrollBarOffset() {
- if (this.ganttMainContent?.nativeElement) {
- const ganttMainContainer = this.ganttMainContent.nativeElement;
- const verticalScrollbarWidth = ganttMainContainer.offsetWidth - ganttMainContainer.clientWidth;
- const horizontalScrollbarHeight = ganttMainContainer.offsetHeight - ganttMainContainer.clientHeight;
- this.verticalScrollbarWidth = verticalScrollbarWidth;
- this.horizontalScrollbarHeight = horizontalScrollbarHeight;
- }
- }
-
expandChildren(item: GanttItemInternal) {
if (!item.expanded) {
item.setExpand(true);
diff --git a/packages/gantt/src/root.component.ts b/packages/gantt/src/root.component.ts
index 0d633c59..1e05a912 100644
--- a/packages/gantt/src/root.component.ts
+++ b/packages/gantt/src/root.component.ts
@@ -10,7 +10,6 @@ import {
Optional,
OnDestroy,
ViewChild,
- AfterViewInit,
HostListener
} from '@angular/core';
import { GanttDomService, ScrollDirection } from './gantt-dom.service';
@@ -31,7 +30,7 @@ import { GanttDate } from './utils/date';
class: 'gantt'
}
})
-export class NgxGanttRootComponent implements OnInit, AfterViewInit, OnDestroy {
+export class NgxGanttRootComponent implements OnInit, OnDestroy {
@Input() sideWidth: number;
@ContentChild('sideTemplate', { static: true }) sideTemplate: TemplateRef;
@@ -87,25 +86,18 @@ export class NgxGanttRootComponent implements OnInit, AfterViewInit, OnDestroy {
this.ganttUpper.viewChange.pipe(startWith(null), takeUntil(this.unsubscribe$)).subscribe(() => {
this.scrollToToday();
});
+ this.updateScrollBarOffset();
});
});
}
- ngAfterViewInit() {
- setTimeout(() => {
- this.updateScrollBarOffset();
- });
- }
-
updateScrollBarOffset() {
- if (this.mainTemplate?.elementRef) {
- const ganttMainContainer =
- this.mainTemplate.elementRef.nativeElement.previousElementSibling.querySelector('.gantt-main').firstChild;
- const verticalScrollbarWidth = ganttMainContainer.offsetWidth - ganttMainContainer.clientWidth;
- const horizontalScrollbarHeight = ganttMainContainer.offsetHeight - ganttMainContainer.clientHeight;
- this.verticalScrollbarWidth = verticalScrollbarWidth;
- this.horizontalScrollbarHeight = horizontalScrollbarHeight;
- }
+ // @ts-ignore
+ const ganttMainContainer = this.dom.mainContainer as HTMLElement;
+ const verticalScrollbarWidth = ganttMainContainer.offsetWidth - ganttMainContainer.clientWidth;
+ const horizontalScrollbarHeight = ganttMainContainer.offsetHeight - ganttMainContainer.clientHeight;
+ this.verticalScrollbarWidth = verticalScrollbarWidth;
+ this.horizontalScrollbarHeight = horizontalScrollbarHeight;
}
ngOnDestroy(): void {