Skip to content

Commit 89a7db9

Browse files
HandsomeButterballwalkerkay
authored andcommitted
feat(table): add gantt side table
1 parent a25d7b8 commit 89a7db9

File tree

12 files changed

+151
-20
lines changed

12 files changed

+151
-20
lines changed

.angulardoc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"repoId": "e269ef2e-9a71-4aa1-8085-f4a738a9cfef",
3+
"lastSync": 0
4+
}
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1-
<ngx-gantt [start]="1514736000" end="1609430400" [items]="items" [groups]="groups"></ngx-gantt>
1+
<ngx-gantt start="1514736000" end="1609430400" [items]="items" [groups]="groups">
2+
<ngx-gantt-column name="标题">
3+
<ng-template #cell let-row>
4+
{{ row.origin.title }}
5+
</ng-template>
6+
</ngx-gantt-column>
7+
<ng-template #group let-group>
8+
{{ group.title }}
9+
</ng-template>
10+
</ngx-gantt>

packages/gantt/src/gantt-upper.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
import { Input, TemplateRef, Output, EventEmitter, ContentChild, ElementRef, HostBinding } from '@angular/core';
1+
import {
2+
Input,
3+
TemplateRef,
4+
Output,
5+
EventEmitter,
6+
ContentChild,
7+
ElementRef,
8+
HostBinding,
9+
ContentChildren,
10+
QueryList,
11+
} from '@angular/core';
212
import {
313
GanttItem,
414
GanttGroup,
@@ -12,6 +22,7 @@ import { GanttView, GanttViewOptions } from './views/view';
1222
import { createViewFactory } from './views/factory';
1323
import { GanttDate } from './utils/date';
1424
import { Subject, fromEvent } from 'rxjs';
25+
import { GanttTableColumnComponent } from './table/column/column.component';
1526

1627
const defaultStyles = {
1728
lineHeight: 55,
@@ -45,9 +56,11 @@ export abstract class GanttUpper {
4556

4657
@Output() dragEnded = new EventEmitter<GanttDragEvent>();
4758

48-
@ContentChild('barTemplate', { static: true }) barTemplate: TemplateRef<any>;
59+
@ContentChild('bar', { static: true }) barTemplate: TemplateRef<any>;
60+
61+
@ContentChild('group', { static: true }) groupTemplate: TemplateRef<any>;
4962

50-
@ContentChild('groupTemplate', { static: true }) groupTemplate: TemplateRef<any>;
63+
@ContentChildren(GanttTableColumnComponent) columns: QueryList<GanttTableColumnComponent>;
5164

5265
public view: GanttView;
5366

packages/gantt/src/gantt.module.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,23 @@ import { GanttContainerComponent } from './layout/gantt-container.component';
66
import { GanttSideComponent } from './layout/gantt-side.component';
77
import { GanttFlatComponent } from './flat/gantt-flat.component';
88
import { GanttBarComponent } from './bar/bar.component';
9+
import { GanttTableColumnComponent } from './table/column/column.component';
10+
import { GanttTableGroupComponent } from './table/group/group.component';
11+
import { GanttTableItemsComponent } from './table/items/items.component';
912

1013
@NgModule({
1114
imports: [CommonModule],
12-
exports: [GanttTableComponent, GanttFlatComponent],
15+
exports: [GanttTableComponent, GanttFlatComponent, GanttTableColumnComponent],
1316
declarations: [
1417
GanttTableComponent,
1518
GanttFlatComponent,
1619
GanttSideComponent,
1720
GanttContainerComponent,
1821
GanttCalendarComponent,
1922
GanttBarComponent,
23+
GanttTableColumnComponent,
24+
GanttTableGroupComponent,
25+
GanttTableItemsComponent,
2026
],
2127
providers: [],
2228
})
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<ng-content></ng-content>

packages/gantt/src/table/column/column.component.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnInit, ContentChild, TemplateRef, Input } from '@angular/core';
22

33
@Component({
4-
selector: 'gantt-table-column',
5-
template: '',
4+
selector: 'ngx-gantt-column',
5+
templateUrl: './column.component.html',
66
})
77
export class GanttTableColumnComponent implements OnInit {
8+
@Input() name: string;
9+
10+
@ContentChild('cell', { static: true }) templateRef: TemplateRef<any>;
11+
812
constructor() {}
913

1014
ngOnInit() {}

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,33 @@
1-
<gantt-side> </gantt-side>
1+
<gantt-side>
2+
<div class="gantt-items-header" *ngIf="columns?.length">
3+
<table>
4+
<thead>
5+
<th *ngFor="let column of columns" [title]="column.name">
6+
{{ column.name }}
7+
</th>
8+
</thead>
9+
</table>
10+
</div>
11+
<div class="gantt-items-container">
12+
<ng-container *ngIf="groups.length; else itemsTemplate">
13+
<gantt-table-group *ngFor="let group of groups" [group]="group" [groupHeader]="groupTemplate">
14+
<gantt-table-items [items]="group.items" [columns]="columns"></gantt-table-items>
15+
</gantt-table-group>
16+
</ng-container>
17+
<ng-template #itemsTemplate
18+
><gantt-table-items [items]="items" [columns]="columns"></gantt-table-items
19+
></ng-template>
20+
</div>
21+
</gantt-side>
222
<gantt-container>
323
<gantt-calendar-overlay *ngIf="view"></gantt-calendar-overlay>
424
<div class="gantt-viewer-container">
525
<!-- groups -->
6-
<div class="gantt-viewer-groups" *ngIf="groups && groups.length > 0; else itemsTemplate" [style.width.px]="view.width">
26+
<div
27+
class="gantt-viewer-groups"
28+
*ngIf="groups && groups.length > 0; else itemsTemplate"
29+
[style.width.px]="view.width"
30+
>
731
<ng-container *ngFor="let group of groups; trackBy: trackBy">
832
<div class="gantt-group"></div>
933
<div class="gantt-items">

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
import {
2-
Component,
3-
OnInit,
4-
ElementRef,
5-
ChangeDetectionStrategy,
6-
Input,
7-
EventEmitter,
8-
Output,
9-
HostBinding,
10-
} from '@angular/core';
1+
import { Component, OnInit, ElementRef, ChangeDetectionStrategy, Input, EventEmitter, Output } from '@angular/core';
112
import { GanttUpper } from '../gantt-upper';
123
import { GanttRef, GANTT_REF_TOKEN } from '../gantt-ref';
134
import { GanttDependencyDragEvent, GanttDependencyEvent, GanttItemInternal } from '../class';
5+
146
@Component({
157
selector: 'ngx-gantt',
168
templateUrl: './gantt-table.component.html',
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div class="gantt-table-group-header">
2+
<ng-template
3+
[ngTemplateOutlet]="groupHeader"
4+
[ngTemplateOutletContext]="{ $implicit: group, group: group }"
5+
></ng-template>
6+
</div>
7+
<ng-content></ng-content>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Component, OnInit, TemplateRef, Input, ViewChild, ElementRef, HostBinding } from '@angular/core';
2+
import { GanttGroup } from '../../class/group';
3+
4+
@Component({
5+
selector: 'gantt-table-group',
6+
templateUrl: './group.component.html',
7+
})
8+
export class GanttTableGroupComponent implements OnInit {
9+
@Input() group: GanttGroup;
10+
11+
@Input() groupHeader: TemplateRef<any>;
12+
13+
@HostBinding('class.gantt-table-group') ganttTableGroupClass = true;
14+
15+
constructor(public elementRef: ElementRef<HTMLDivElement>) {}
16+
17+
ngOnInit() {}
18+
}

0 commit comments

Comments
 (0)