Skip to content

Commit

Permalink
fix: fix ngx-gantt-table itemClick event not work #472
Browse files Browse the repository at this point in the history
  • Loading branch information
walkerkay committed Nov 5, 2024
1 parent 8aaad19 commit 4c0bdbb
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions example/src/app/gantt/gantt.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<ngx-gantt-table
[draggable]="true"
[dropEnterPredicate]="dropEnterPredicate"
(itemClick)="itemClick($event)"
(dragDropped)="onDragDropped($event)"
(dragStarted)="onDragStarted($event)"
(dragEnded)="onDragEnded($event)"
Expand Down
5 changes: 5 additions & 0 deletions example/src/app/gantt/gantt.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
GanttTableDragEndedEvent,
GanttTableDragEnterPredicateContext,
GanttTableDragStartedEvent,
GanttTableItemClickEvent,
GanttToolbarOptions,
GanttView,
GanttViewType,
Expand Down Expand Up @@ -163,6 +164,10 @@ export class AppGanttExampleComponent implements OnInit, AfterViewInit {
this.items = [...this.items];
}

itemClick(event: GanttTableItemClickEvent) {
console.log(`点击了数据行 ${event.current.id}`);
}

selectedChange(event: GanttSelectedEvent) {
event.current && this.ganttComponent.scrollToDate(event.current?.start);

Expand Down
5 changes: 4 additions & 1 deletion packages/gantt/src/class/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ export class GanttBarClickEvent<T = unknown> {
item: GanttItem<T>;
}

export class GanttSelectedEvent<T = unknown> {
export class GanttTableItemClickEvent<T = unknown> {
event: Event;
current?: GanttItem<T>;
}

export class GanttSelectedEvent<T = unknown> extends GanttTableItemClickEvent<T> {
selectedValue: GanttItem<T> | GanttItem<T>[];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

<div
*ngIf="!item.items"
(click)="itemClick.emit({ event: $event, selectedValue: item.origin })"
(click)="itemClick.emit({ event: $event, current: item.origin, selectedValue: item.origin })"
cdkDrag
[cdkDragData]="item"
[cdkDragDisabled]="(draggable && item.itemDraggable === false) || !draggable"
Expand Down
5 changes: 5 additions & 0 deletions packages/gantt/src/gantt.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ export class NgxGanttComponent extends GanttUpper implements OnInit, OnChanges,
}

selectItem(selectEvent: GanttSelectedEvent) {
this.table.itemClick.emit({
event: selectEvent.event,
current: selectEvent.current
});

if (!this.selectable) {
return;
}
Expand Down
7 changes: 5 additions & 2 deletions packages/gantt/src/table/gantt-table.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Component, ContentChild, EventEmitter, Input, Output, TemplateRef } from '@angular/core';
import { Component, ContentChild, EventEmitter, input, Input, Output, TemplateRef } from '@angular/core';
import {
GanttTableDragEnterPredicateContext,
GanttTableDragDroppedEvent,
GanttTableEvent,
GanttTableDragStartedEvent,
GanttTableDragEndedEvent
GanttTableDragEndedEvent,
GanttTableItemClickEvent
} from '../class';

@Component({
Expand All @@ -25,6 +26,8 @@ export class NgxGanttTableComponent {

@Output() columnChanges = new EventEmitter<GanttTableEvent>();

@Output() itemClick = new EventEmitter<GanttTableItemClickEvent>();

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

@ContentChild('rowAfterSlot', { static: true }) rowAfterTemplate: TemplateRef<any>;
Expand Down

0 comments on commit 4c0bdbb

Please sign in to comment.