React Scheduler - Add Appointments

User Interaction

To add an appointment, a user follows the steps listed below.

  1. Clicks a cell in the timetable to set focus on it.
  2. Clicks the focused cell once again. The appointment details form will be shown.
  3. In the form, specifies required fields and clicks the "Done" button. This will create an appointment and add it to the data source.

To prevent an end user from adding an appointment, set the editing.allowAdding property to false.

HTML
TypeScript
  • <dx-scheduler ... >
  • <dxo-editing [allowAdding]="false"></dxo-editing>
  • </dx-scheduler>
  • import { DxSchedulerModule } from "devextreme-angular";
  • // ...
  • export class AppComponent {
  • // ...
  • }
  • @NgModule({
  • imports: [
  • // ...
  • DxSchedulerModule
  • ],
  • // ...
  • })

API

To add an appointment to the data source, call the addAppointment(appointment) method. Note that the structure of the added appointment should be the same as the UI component's data source items.

HTML
TypeScript
  • <dx-scheduler
  • [(dataSource)]="appointments"
  • [currentDate]="currentDate">
  • </dx-scheduler>
  •  
  • <dx-button
  • text="Add"
  • (onClick)="addAppointment()">
  • </dx-button>
  • import { ..., ViewChild } from "@angular/core";
  • import { DxButtonModule, DxSchedulerModule, DxSchedulerComponent } from "devextreme-angular";
  • // ...
  • export class AppComponent {
  • @ViewChild(DxSchedulerComponent, { static: false }) scheduler: DxSchedulerComponent;
  • // Prior to Angular 8
  • // @ViewChild(DxSchedulerComponent) scheduler: DxSchedulerComponent;
  • appointments = [{
  • text: "Planning",
  • startDate: new Date("2016-04-25T09:00:00.000Z"),
  • endDate: new Date("2016-04-25T09:30:00.000Z")
  • },
  • // ...
  • ];
  • currentDate = new Date(2016, 4, 25);
  •  
  • addAppointment() {
  • this.scheduler.instance.addAppointment({
  • text: "Website Re-Design Plan",
  • startDate: new Date("2016-04-25T01:30:00.000Z"),
  • endDate: new Date("2016-04-25T02:30:00.000Z")
  • });
  • }
  • }
  • @NgModule({
  • imports: [
  • // ...
  • DxSchedulerModule,
  • DxButtonModule
  • ],
  • // ...
  • })

Events

To execute certain commands before or after an appointment was added, handle the appointmentAdding or appointmentAdded event. If the event handling function is not going to be changed during the lifetime of the UI component, assign it to the corresponding onEventName property when you configure the UI component.

HTML
TypeScript
  • <dx-scheduler ...
  • (onAppointmentAdding)="onAppointmentAdding($event)"
  • (onAppointmentAdded)="onAppointmentAdded($event)">
  • </dx-scheduler>
  • import { DxSchedulerModule } from "devextreme-angular";
  • // ...
  • export class AppComponent {
  • onAppointmentAdding (e) {
  • // Handler of the "appointmentAdding" event
  • }
  •  
  • onAppointmentAdded (e) {
  • // Handler of the "appointmentAdded" event
  • }
  • }
  • @NgModule({
  • imports: [
  • // ...
  • DxSchedulerModule
  • ],
  • // ...
  • })
See Also