Kendo UI Scheduler usage

For displaying the data from a Smart DataSource in a Kendo UI Scheduler component, please follow the steps:

  1. Create a new Angular project (ng new SchedulerDemo)

  2. Install the Smart Component Library (scl install)

  • specify the serviceURI: https://jenkins.consultingwerkcloud.com:8871/registered

3. Generate a new JSON layout-based form (scheduler.form.ts) with the following settings:

  • path: ‘schedule’

  • formId: 'schedule;

After generation ensure that the setConfiguration call is done with the JSON layout file name (that will be created on step #5):

this.setFormConfiguration('frontend://assets/schedule.layout.json');

4. Install the npm modules:

  • @progress/kendo-angular-intl

  • @progress/kendo-angular-dateinputs

  • @progress/kendo-angular-buttons

  • @progress/kendo-angular-label

  • @progress/kendo-angular-scheduler

using the command in the terminal:

npm install --save @progress/kendo-angular-intl @progress/kendo-angular-dateinputs @progress/kendo-angular-buttons @progress/kendo-angular-label @progress/kendo-angular-scheduler

5. Create the JSON layout in the /assets folder (schedule.layout.json)

6. Add the settings for the Smart DataSource:

"dataSources": { "ScheduleDataSource": { "objectName": "ScheduleDataSource", "entityName": "Consultingwerk.ConferenceApp.Backend.Presentations.ConferencePresentationBusinessEntity", "tableRef": "eConferencePresentation" } },

7. Add a custom component in the JSON layout:

"schedule": { "componentType": "custom", "componentOptions": { "placeholderId": "schedule" } }

8. From the terminal, go to the /src/app/forms/scheduler and run the command

ng generate component schedule, to generate the Angular component for the custom component (added in the JSON layout)

9. In the /forms/scheduler folder create the file schedule.service.ts with the following content:

import { Injectable, OnInit } from "@angular/core"; import { DataSourceRegistry, SmartDataSource } from "@consultingwerk/smartcomponent-library"; import { SchedulerEvent } from "@progress/kendo-angular-scheduler"; import { ReplaySubject } from "rxjs"; import { switchMap, tap } from "rxjs/operators"; import { ScheduleEvent } from "./schedule-event.model"; @Injectable() export class ScheduleService { // the Smart DataSource instance private scheduleDs: SmartDataSource; // an observable array containing the events objects retrieved from the scheduleDs readonly schedule: ReplaySubject<SchedulerEvent[]> = new ReplaySubject<SchedulerEvent[]>(); getSchedule() { this.scheduleDs.fetch().then((data) => { const events: SchedulerEvent[] = []; data.data.forEach(ev => { // convert each object into an object of type accepted by the Kendo Scheduler (SchedulerEvent) events.push(this.convertToSchedulerEvent(ev)); }) this.schedule.next(events); }) } setDatasource(ds: SmartDataSource) { this.scheduleDs = ds; this.getSchedule(); } convertToSchedulerEvent(ev: ScheduleEvent): SchedulerEvent { const schedulerEv: SchedulerEvent = { id: ev.id, title: ev.SessionTitle, start: ev.SessionStartTime, end: new Date(ev.SessionStartTime.getTime() + ev.SessionDuration*60000) }; return schedulerEv; } }
  • setDatasource method sets the datasource from which the data will be retrieved. It is set from the .ts file of the form component.

  • getSchedule method is used to get the data

  • convertToSchedulerEvent method transforms an object as it comes from the backend into an object of type SchedulerEvent (as the Kendo Scheduler expects the array of events to be)

10. Open the schedule.component.ts file (the custom component that was generated) and add the SmartCustomComponent annotation with the placeholder from the JSON layout:

@SmartCustomComponent('schedule')

This should be placed above the @Component annotation.

11. The class will extend the AbstractFormChild class. Implement the required method handleLayoutChange (the method can be left empty)

12. Add the variables:

// binds the selected date from the Kendo Date Picker and the selected date from the Kendo Scheduler selectedDate: Date = new Date('11/09/2021'); // used for the user to be able to select a slotin the Kendo Scheduler selectedSlot: SlotRange; // the events that were retrieved from the Smart DataSource and bound to the Kendo Scheduler to be displayed events: SchedulerEvent[];

13. In the constructor, add the following to the parameters:

private scheduleService: ScheduleService, private dsRegistry: DataSourceRegistry
  • schedulerService is the service that was created on step #9, to get and compute the events from the backend

  • dsRegistry is used to get the instance of the ScheduleDataSource created on step #6

14. In the ngOnInit method get the Smart DataSource instance:

this.dsRegistry.getDataSourceAsObservable('ScheduleDataSource').subscribe(ds => { this.scheduleService.setDatasource(ds); })

and subscribe to the scheduler events from the schedule.service.ts (the readonly ReplaySubject schedule variable):

this.scheduleService.schedule.subscribe(data => { this.events = data; })

This way when the events are fetched from the Smart DataSOurce in the service, they will be updated in the custom component (which contains the Kendo Scheduler component)

15. Go to the scheduler.form.ts file -> @NgModule annotation and add the ScheduleComponent (the custom component) to the declarations and entryComponents sections. Also add it in the SchedulerFormModule's static entryComponents array:

static entryComponents = [ SchedulerFormComponent, ScheduleComponent ];

16. Add the ScheduleService to the scheduler.form.ts file -> @NgModule annotation.

17. For the custom component HTML template, add in schedule.component.html:

<span>Select a date: </span> <kendo-datepicker [(value)]="selectedDate"></kendo-datepicker> <br><br> <kendo-scheduler [kendoSchedulerBinding]="events" [selectedDate]="selectedDate" style="height: 600px;" kendoSchedulerSlotSelectable [(slotSelection)]="selectedSlot"> <kendo-scheduler-day-view></kendo-scheduler-day-view> <kendo-scheduler-week-view startTime="07:00"> </kendo-scheduler-week-view> <kendo-scheduler-month-view></kendo-scheduler-month-view> </kendo-scheduler>

The Kendo DatePicker element is used to select a date, which is then passed to the Kendo Scheduler element. This way when the user selects a date, the Kendo Scheduler will react to it.

The Kendo Scheduler displays the events that are bound with the kendoSchedulerBinding attribute.

The attributes kendoSchedulerSlotSelectable [(slotSelection)]="selectedSlot" allow the user to select a slot in the scheduler table. Nothing will happen when a slot is selected, excepting the slot will be coloured differently, for the user to see the selection.

 

The final project structure should look like in the screenshot below:

Please check the relevant code files attached to this page for further reference.