Skip to content

Commit

Permalink
feat: support column inherits the class when gantt-table-column sets …
Browse files Browse the repository at this point in the history
…class #INFR-6999
  • Loading branch information
ark-65 authored and HandsomeButterball committed Mar 24, 2023
1 parent 00d70be commit 81f37c9
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion example/src/app/gantt/gantt.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
(linkDragEnded)="linkDragEnded($event)"
>
<ngx-gantt-table [draggable]="true" [dropEnterPredicate]="dropEnterPredicate" (dragDropped)="onDragDropped($event)">
<ngx-gantt-column name="开始时间" [width]="140">
<ngx-gantt-column name="开始时间" [class.start-time]="true" [width]="140">
<ng-template #cell let-item="item">
{{ item.id }}
</ng-template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
[ngTemplateOutletContext]="{ $implicit: item.origin, item: item.origin }"
></ng-template>

<div class="gantt-table-column" *ngFor="let column of columns; let first = first" [style.width]="column.columnWidth">
<div [classList]="column.classList" *ngFor="let column of columns; let first = first" [style.width]="column.columnWidth">
<!-- drag icon -->
<gantt-icon
*ngIf="first && draggable"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export class GanttTableBodyComponent implements OnInit, OnDestroy, AfterViewInit
this.columns.changes.pipe(startWith(this.columns), takeUntil(this.destroy$)).subscribe(() => {
this.hasExpandIcon = false;
this.columns.forEach((column) => {
column.classList.add('gantt-table-column');
if (!column.columnWidth) {
column.columnWidth = coerceCssPixelValue(defaultColumnWidth);
}
Expand Down
8 changes: 6 additions & 2 deletions packages/gantt/src/table/gantt-column.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, ContentChild, TemplateRef, Input, Inject } from '@angular/core';
import { Component, ContentChild, TemplateRef, Input, Inject, ElementRef } from '@angular/core';
import { coerceCssPixelValue } from '@angular/cdk/coercion';
import { GanttUpper, GANTT_UPPER_TOKEN } from '../gantt-upper';
@Component({
Expand All @@ -21,5 +21,9 @@ export class NgxGanttTableColumnComponent {

@ContentChild('header', { static: true }) headerTemplateRef: TemplateRef<any>;

constructor(@Inject(GANTT_UPPER_TOKEN) public ganttUpper: GanttUpper) {}
constructor(@Inject(GANTT_UPPER_TOKEN) public ganttUpper: GanttUpper, private elementRef: ElementRef) {}

get classList(): DOMTokenList {
return this.elementRef.nativeElement.classList;
}
}
19 changes: 18 additions & 1 deletion packages/gantt/src/test/gantt.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ const config = {
<ng-template #rowAfterSlot>
<div class="row-after"></div>
</ng-template>
<ngx-gantt-column name="标题" width="200px">
<ngx-gantt-column
name="标题"
width="200px"
[class.title-name]="true"
[ngClass]="{ 'title-name-2': true }"
[class]="'title-name-3'"
>
<ng-template #cell let-item="item">
{{ item.title }}
</ng-template>
Expand Down Expand Up @@ -464,6 +470,17 @@ describe('ngx-gantt', () => {
loaderDom = fixture.debugElement.query(By.directive(GanttLoaderComponent));
expect(loaderDom).toBeFalsy();
}));

it('should column inherits the class when gantt-table-column sets class"', fakeAsync(() => {
const newItems = mockItems.slice(0, 1);
ganttComponentInstance.items = [...newItems];
fixture.detectChanges();
const ganttTable: DebugElement = ganttDebugElement.query(By.directive(GanttTableBodyComponent));
const ganttTableColumn = ganttTable.query(By.css('.gantt-table-column')).nativeElement;
expect(ganttTableColumn.classList).toContain('title-name');
expect(ganttTableColumn.classList).toContain('title-name-2');
expect(ganttTableColumn.classList).toContain('title-name-3');
}));
});

describe('#with groups', () => {
Expand Down

0 comments on commit 81f37c9

Please sign in to comment.