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.

JavaScript
$(function() {
    $("#schedulerContainer").dxScheduler({
        // ...
        editing: { allowAdding: false }
    });
});

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.

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)
            });
        }
    });
});

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.

JavaScript
$(function () {
    $("#schedulerContainer").dxScheduler({
        // ...
        onAppointmentAdding: function (e) {
            // Handler of the "appointmentAdding" event
        },
        onAppointmentAdded: function (e) {
            // Handler of the "appointmentAdded" event
        }
    });
});

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.

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