Skip to content

Commit 5108e2b

Browse files
authored
fix(gantt): 修复win系统,左侧表格横向滚轴按钮不生效,滚动条在可视窗口展示 (#555)
1 parent bdf1f6c commit 5108e2b

File tree

8 files changed

+23
-14
lines changed

8 files changed

+23
-14
lines changed

packages/gantt/src/components/scrollbar/scrollbar.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
[style.height.px]="ganttRoot?.horizontalScrollbarHeight + 1"
55
[style.right.px]="ganttRoot?.verticalScrollbarWidth"
66
>
7-
<div class="gantt-table-scrollbar" [class.with-scrollbar]="ganttRoot?.horizontalScrollbarHeight" [style.width.px]="tableWidth"></div>
7+
<div class="gantt-table-scrollbar" [class.with-scrollbar]="ganttRoot?.horizontalScrollbarHeight" [style.width.px]="tableWidth">
8+
<div class="h-100" [style.width.px]="ganttRoot.ganttUpper['ganttTableBody']?.elementRef?.nativeElement?.offsetWidth - 1 || 0"></div>
9+
</div>
810
<div class="gantt-main-scrollbar">
911
<div class="h-100" [style.width.px]="ganttRoot['view']?.width"></div>
1012
</div>

packages/gantt/src/components/table/body/gantt-table-body.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
</div>
9090
</div>
9191
}
92-
<div class="gantt-table-column"></div>
92+
<div class="gantt-table-column gantt-table-column-placeholder"></div>
9393
<ng-template
9494
[ngTemplateOutlet]="rowAfterTemplate"
9595
[ngTemplateOutletContext]="{ $implicit: item.origin, item: item.origin }"

packages/gantt/src/components/table/body/gantt-table-body.component.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
AfterViewInit,
66
ChangeDetectorRef,
77
Component,
8+
ElementRef,
89
EventEmitter,
910
HostBinding,
1011
Inject,
@@ -113,11 +114,14 @@ export class GanttTableBodyComponent implements OnInit, OnDestroy, AfterViewInit
113114

114115
public footerContainer: Element;
115116

117+
public tableScrollbarContainer: Element;
118+
116119
constructor(
117120
@Inject(GANTT_ABSTRACT_TOKEN) public gantt: GanttAbstractComponent,
118121
@Inject(GANTT_UPPER_TOKEN) public ganttUpper: GanttUpper,
119122
private cdr: ChangeDetectorRef,
120123
@Inject(DOCUMENT) private document: Document,
124+
protected elementRef: ElementRef<HTMLElement>,
121125
private ngZone: NgZone
122126
) {}
123127

@@ -166,27 +170,25 @@ export class GanttTableBodyComponent implements OnInit, OnDestroy, AfterViewInit
166170
this.sideContainer = this.document.getElementsByClassName('gantt-side-container')[0];
167171
this.headerContainer = this.document.getElementsByClassName('gantt-table-header-container')[0];
168172
this.footerContainer = this.document.getElementsByClassName('gantt-table-footer')[0];
173+
this.tableScrollbarContainer = this.document.getElementsByClassName('gantt-table-scrollbar')[0];
169174
this.monitorScrollChange();
170175
}
171176

172177
private monitorScrollChange() {
173178
const scrollObservers = [
174179
fromEvent(this.sideContainer, 'scroll', passiveListenerOptions),
175-
fromEvent(this.headerContainer, 'scroll', passiveListenerOptions)
180+
fromEvent(this.headerContainer, 'scroll', passiveListenerOptions),
181+
fromEvent(this.tableScrollbarContainer, 'scroll', passiveListenerOptions)
176182
];
177183
this.ngZone.runOutsideAngular(() =>
178184
merge(...scrollObservers)
179185
.pipe(takeUntil(this.destroy$))
180186
.subscribe((event) => {
181187
const target = event.currentTarget as HTMLElement;
182-
const classList = target.classList;
183-
if (classList.contains('gantt-table-header-container')) {
184-
this.sideContainer && (this.sideContainer.scrollLeft = target.scrollLeft);
185-
this.footerContainer && (this.footerContainer.scrollLeft = target.scrollLeft);
186-
} else {
187-
this.headerContainer && (this.headerContainer.scrollLeft = target.scrollLeft);
188-
this.footerContainer && (this.footerContainer.scrollLeft = target.scrollLeft);
189-
}
188+
this.headerContainer && (this.headerContainer.scrollLeft = target.scrollLeft);
189+
this.sideContainer && (this.sideContainer.scrollLeft = target.scrollLeft);
190+
this.tableScrollbarContainer && (this.tableScrollbarContainer.scrollLeft = target.scrollLeft);
191+
this.footerContainer && (this.footerContainer.scrollLeft = target.scrollLeft);
190192
})
191193
);
192194
}

packages/gantt/src/components/table/gantt-table.scss

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
border-right: none;
1717
}
1818

19-
&:last-child {
19+
&.gantt-table-column-placeholder {
2020
padding: 0;
2121
border: 1px solid variables.$gantt-border-color;
2222
border-right: none;
@@ -70,7 +70,7 @@
7070
&:nth-last-child(2) {
7171
border-right: none;
7272
}
73-
&:last-child {
73+
&.gantt-table-column-placeholder {
7474
padding: 0;
7575
border: 1px solid variables.$gantt-border-color;
7676
border-right: none;
@@ -205,6 +205,7 @@
205205

206206
.gantt-table-body {
207207
display: block;
208+
flex: 1;
208209
.gantt-table-group {
209210
display: flex;
210211
background: variables.$gantt-group-background-color;

packages/gantt/src/components/table/header/gantt-table-header.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
></div>
1818
</div>
1919
}
20-
<div class="gantt-table-column"></div>
20+
<div class="gantt-table-column gantt-table-column-placeholder"></div>
2121
</div>
2222

2323
@if (gantt?.table?.settingsSlot) {

packages/gantt/src/gantt.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<div class="gantt-side-container">
2828
<div class="gantt-table">
2929
<gantt-table-body
30+
#ganttTableBody
3031
[flatItems]="flatItems"
3132
[viewportItems]="viewportItems"
3233
[columns]="columns"

packages/gantt/src/gantt.component.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
.gantt-table {
3535
height: 100%;
3636
flex: 1;
37+
display: flex;
3738
}
3839

3940
&::-webkit-scrollbar {

packages/gantt/src/gantt.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ export class NgxGanttComponent extends GanttUpper implements OnInit, OnChanges,
136136

137137
@ViewChild(CdkVirtualScrollViewport) virtualScroll: CdkVirtualScrollViewport;
138138

139+
@ViewChild('ganttTableBody', { static: true }) ganttTableBody: ElementRef<HTMLDivElement>;
140+
139141
get loading() {
140142
return this._loading;
141143
}

0 commit comments

Comments
 (0)