|
| 1 | +import { Component, ViewChild } from '@angular/core'; |
| 2 | +import { CellClickEventArgs, EventSettingsModel, ScheduleComponent } from '@syncfusion/ej2-angular-schedule'; |
| 3 | +import { hospitalData, waitingList } from './data'; |
| 4 | +import { DragAndDropEventArgs, TreeViewComponent } from '@syncfusion/ej2-angular-navigations'; |
| 5 | +import { closest} from '@syncfusion/ej2-base'; |
| 6 | +@Component({ |
| 7 | + selector: 'app-root', |
| 8 | + templateUrl: './app.component.html', |
| 9 | + styleUrls: ['./app.component.css'] |
| 10 | +}) |
| 11 | +export class AppComponent { |
| 12 | + title = 'myangularproject'; |
| 13 | + @ViewChild('treeview') treeviewObj !: TreeViewComponent; |
| 14 | + @ViewChild('schedule') schedulerObj !: ScheduleComponent; |
| 15 | + public eventSettings: EventSettingsModel = { |
| 16 | + dataSource: hospitalData, |
| 17 | + }; |
| 18 | + |
| 19 | + public field: Record<string, any> = { dataSource: waitingList, id: 'Id', text: 'Name' } |
| 20 | + |
| 21 | + public onDragStop(args: DragAndDropEventArgs){ |
| 22 | + let scheduleElem: Element = closest(args.target, '.e-content-wrap') as Element; |
| 23 | + if(scheduleElem && args.target.classList.contains('e-work-cells')){ |
| 24 | + let treeViewData: Record<string, any>[] = this.treeviewObj.fields.dataSource as Record<string, any>[]; |
| 25 | + let filteredData: Record<string, any>[] = treeViewData.filter( |
| 26 | + (item: any) => item.Id === parseInt(args.draggedNodeData['id'] as string, 10) |
| 27 | + ); |
| 28 | + let cellData: CellClickEventArgs = this.schedulerObj.getCellDetails(args.target); |
| 29 | + let eventData: Record<string, any> = { |
| 30 | + Id: this.schedulerObj.getEventMaxID(), |
| 31 | + Subject: filteredData[0]['Name'], |
| 32 | + Description: filteredData[0]['Description'], |
| 33 | + StartTime: cellData.startTime, |
| 34 | + EndTime: cellData.endTime, |
| 35 | + IsAllDay: cellData.isAllDay |
| 36 | + } |
| 37 | + this.schedulerObj.openEditor(eventData, 'Add', true); |
| 38 | + let updatedList: Record<string, any>[] = treeViewData.filter( |
| 39 | + (item: any) => item.Id !== parseInt(args.draggedNodeData['id'] as string, 10) |
| 40 | + ); |
| 41 | + this.treeviewObj.fields.dataSource = updatedList; |
| 42 | + } |
| 43 | + } |
| 44 | +} |
0 commit comments