All docs
V19.1
24.1
The page you are viewing does not exist in version 24.1.
23.2
The page you are viewing does not exist in version 23.2.
23.1
The page you are viewing does not exist in version 23.1.
22.2
The page you are viewing does not exist in version 22.2.
22.1
The page you are viewing does not exist in version 22.1.
21.2
The page you are viewing does not exist in version 21.2.
21.1
The page you are viewing does not exist in version 21.1.
20.2
The page you are viewing does not exist in version 20.2.
20.1
The page you are viewing does not exist in version 20.1.
19.2
19.1
18.2
18.1
17.2
A newer version of this page is available. Switch to the current version.

DevExtreme jQuery - 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 option to false.

jQuery
JavaScript
$(function() {
    $("#schedulerContainer").dxScheduler({ 
        // ...
        editing: { allowAdding: false }
    });
});
Angular
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 widget's data source items.

jQuery
JavaScript
$(function() {
    var scheduler = $("#schedulerContainer").dxScheduler({
        dataSource: [{
            text: "Planning",
            startDate: new Date(2016, 4, 25, 9, 00),
            endDate: new Date(2016, 4, 25, 9, 30)
        }, 
        // ...
        ],
        currentDate: new Date(2016, 4, 25)
    }).dxScheduler("instance");

    $("#addButton").dxButton({
        text: "Add",
        onClick: function () {
            scheduler.addAppointment({
                text: "Website Re-Design Plan",
                startDate: new Date(2016, 4, 25, 9, 30),
                endDate: new Date(2016, 4, 25, 11, 30)
            });
        }
    });
});
Angular
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, 4, 25, 9, 0),
        endDate: new Date(2016, 4, 25, 9, 30)
    }, 
    // ...
    ];
    currentDate = new Date(2016, 4, 25);

    addAppointment() {
        this.scheduler.instance.addAppointment({
            text: "Website Re-Design Plan",
            startDate: new Date(2016, 4, 25, 1, 30),
            endDate: new Date(2016, 4, 25, 2, 30)
        });
    }
}
@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 widget, assign it to the corresponding onEventName option when you configure the widget.

jQuery
JavaScript
$(function () {
    $("#schedulerContainer").dxScheduler({ 
        // ...
        onAppointmentAdding: function (e) {
            // Handler of the "appointmentAdding" event
        },
        onAppointmentAdded: function (e) {
            // Handler of the "appointmentAdded" event
        }
    });
});
Angular
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
    ],
    // ...
})

If you are going to change event handlers at runtime, or if you need to attach several handlers to a single event, subscribe to the event using the on(eventName, eventHandler) method. This approach is more typical of jQuery.

JavaScript
var addedEventHandler1 = function (e) {
    // First handler of the "added" event
};

var addedEventHandler2 = function (e) {
    // Second handler of the "added" event
};

$("#schedulerContainer").dxScheduler("instance")
    .on("appointmentAdded", addedEventHandler1)
    .on("appointmentAdded", addedEventHandler2);
See Also