|
| 1 | +import { Component, ViewChild } from '@angular/core'; |
| 2 | +import { EventSettingsModel, ExportFieldInfo, ExportOptions, ScheduleComponent, ToolbarActionArgs } from '@syncfusion/ej2-angular-schedule'; |
| 3 | +import { ItemModel } from '@syncfusion/ej2-navigations'; |
| 4 | +import { scheduleData } from './data'; |
| 5 | +@Component({ |
| 6 | + selector: 'app-root', |
| 7 | + templateUrl: './app.component.html', |
| 8 | + styleUrls: ['./app.component.css'] |
| 9 | +}) |
| 10 | +export class AppComponent { |
| 11 | + title = 'myangularproject'; |
| 12 | + @ViewChild('scheduler') schedulerObj !: ScheduleComponent; |
| 13 | + public selectedDate: Date = new Date(2023, 9, 9); |
| 14 | + public eventSettings: EventSettingsModel = { dataSource: scheduleData }; |
| 15 | + |
| 16 | + public onActionBegin(args: ToolbarActionArgs){ |
| 17 | + if(args.requestType === 'toolbarItemRendering'){ |
| 18 | + let exportItem: ItemModel = { |
| 19 | + text: 'Excel Export', |
| 20 | + prefixIcon: 'e-icon-schedule-excel-export', |
| 21 | + click: this.onExportClick.bind(this) |
| 22 | + }; |
| 23 | + args.items?.push(exportItem); |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + public onExportClick(){ |
| 28 | + let customFields: ExportFieldInfo[] = [ |
| 29 | + { name:'Subject', text:'Summary'}, |
| 30 | + { name: 'StartTime', text: 'First Date' }, |
| 31 | + { name: 'EndTime', text: 'Last Date' }, |
| 32 | + ] |
| 33 | + let options: ExportOptions = { |
| 34 | + fields: ['Id', 'Subject', 'StartTime', 'EndTime', 'Location'], |
| 35 | + fieldsInfo: customFields, |
| 36 | + fileName: 'Appointments', |
| 37 | + includeOccurrences: false, |
| 38 | + exportType: 'csv', |
| 39 | + customData: [ |
| 40 | + {Id: 1, Subject: 'Scrum Meeting', StartTime: new Date(2019, 0, 6, 9, 30), EndTime: new Date(2019, 0, 6, 11, 0)}, |
| 41 | + {Id: 2, Subject: 'PO Meeting', StartTime: new Date(2019, 0, 7, 9, 30), EndTime: new Date(2019, 0, 7, 11, 0)}, |
| 42 | + {Id: 3, Subject: 'Lead Training', StartTime: new Date(2019, 0, 8, 9, 30), EndTime: new Date(2019, 0, 8, 11, 0)}] |
| 43 | + } |
| 44 | + this.schedulerObj.exportToExcel(options); |
| 45 | + } |
| 46 | +} |
0 commit comments