User Interaction
An end user can update an appointment in one of the following ways.
- Reschedule an appointment by moving it to another cell.
- Extend or shorten an appointment by dragging its top or bottom border.
- Change the appointment details by focusing the appointment and clicking "Open Appointment" afterwards.
When a user finishes updates, they are saved to the dataSource.
If a user updates a recurring appointment, the Scheduler displays a dialog where users can choose between editing the current appointment and editing the entire series of recurring appointments. If you do not want this dialog to appear, choose the edit mode beforehand using the recurrenceEditMode property.
jQuery
$(function() { $("#schedulerContainer").dxScheduler({ // ... recurrenceEditMode: 'occurrence' // or 'series' | 'dialog' }); });
Angular
<dx-scheduler ... recurrenceEditMode="occurrence"> <!-- or 'series' | 'dialog' --> </dx-scheduler>
import { DxSchedulerModule } from "devextreme-angular"; // ... export class AppComponent { // ... } @NgModule({ imports: [ // ... DxSchedulerModule ], // ... })
Vue
<template> <DxScheduler recurrence-edit-mode="occurrence" /> <!-- or 'series' | 'dialog' --> </template> <script> import 'devextreme/dist/css/dx.light.css'; import { DxScheduler } from 'devextreme-vue/scheduler'; export default { components: { DxScheduler } } </script>
React
import React from 'react'; import 'devextreme/dist/css/dx.light.css'; import { Scheduler } from 'devextreme-react/scheduler'; class App extends React.Component { render() { return ( <Scheduler recurrenceEditMode="occurrence" /> {/* or 'series' | 'dialog' */} ); } } export default App;
To prevent a user from updating an appointment, set the editing.allowUpdating property to false.
jQuery
$(function() { $("#schedulerContainer").dxScheduler({ // ... editing: { allowUpdating: false } }); });
Angular
<dx-scheduler ... > <dxo-editing [allowUpdating]="false"></dxo-editing> </dx-scheduler>
import { DxSchedulerModule } from "devextreme-angular"; // ... export class AppComponent { // ... } @NgModule({ imports: [ // ... DxSchedulerModule ], // ... })
Vue
<template> <DxScheduler <DxEditing :allow-updating="false" /> /DxScheduler> </template> <script> import 'devextreme/dist/css/dx.light.css'; import { DxScheduler, DxEditing } from 'devextreme-vue/scheduler'; export default { components: { DxScheduler } } </script>
React
import React from 'react'; import 'devextreme/dist/css/dx.light.css'; import { Scheduler, Editing } from 'devextreme-react/scheduler'; class App extends React.Component { render() { return ( <Scheduler ... > <Editing allowUpdating={false} /> </Scheduler> ); } } export default App;
API
To update an appointment, call the updateAppointment(target, appointment) method. This method updates the target appointment from the data source with the fields of the appointment parameter.
jQuery
$(function() { var appointments = [{ text: "Website Re-Design Plan", startDate: new Date("2016-04-25T09:00:00.000Z"), endDate: new Date("2016-04-25T09:30:00.000Z") }, // ... ]; var scheduler = $("#schedulerContainer").dxScheduler({ dataSource: appointments, currentDate: new Date(2016, 4, 25) }).dxScheduler("instance"); $("#modifyButton").dxButton({ text: "Modify", onClick: function () { scheduler.updateAppointment(appointments[0], { text: "Planning" } ); } }); });
Angular
<dx-scheduler [(dataSource)]="appointments" [currentDate]="currentDate"> </dx-scheduler> <dx-button text="Update" (onClick)="updateAppointment()"> </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: "Website Re-Design Plan", startDate: new Date("2016-04-25T09:00:00.000Z"), endDate: new Date("2016-04-25T09:30:00.000Z") }, // ... ]; currentDate = new Date(2016, 4, 25); updateAppointment() { this.scheduler.instance.updateAppointment(this.appointments[0], { text: "Planning" } ); } } @NgModule({ imports: [ // ... DxSchedulerModule, DxButtonModule ], // ... })
Vue
<template> <div> <DxScheduler ref="scheduler" :data-source="appointments" :current-date="currentDate" /> <DxButton text="Update" @click="updateAppointment" /> </div> </template> <script> import 'devextreme/dist/css/dx.light.css'; import DxScheduler from 'devextreme-vue/scheduler'; import DxButton from 'devextreme-vue/button'; export default { components: { DxScheduler, DxButton }, data() { return { appointments: [{ text: "Website Re-Design Plan", startDate: new Date("2016-04-25T09:00:00.000Z"), endDate: new Date("2016-04-25T09:30:00.000Z") }, // ... ], currentDate: new Date(2016, 4, 25) }, methods: { updateAppointment(e) { this.$refs['scheduler'].instance.updateAppointment(this.appointments[0], { text: "Planning" }); } } } } </script>
React
import React from 'react'; import 'devextreme/dist/css/dx.light.css'; import Scheduler from 'devextreme-react/scheduler'; import Button from 'devextreme-react/button'; const appointments = [{ text: "Website Re-Design Plan", startDate: new Date("2016-04-25T09:00:00.000Z"), endDate: new Date("2016-04-25T09:30:00.000Z") }, // ... ]; class App extends React.Component { constructor(props) { super(props); this.schedulerRef = React.createRef(); this.updateAppointment = this.updateAppointment.bind(this); } get scheduler() { return this.schedulerRef.current.instance(); } updateAppointment() { this.scheduler.updateAppointment(this.appointments[0], { text: "Planning" }); } render() { return ( <React.Fragment> <Scheduler dataSource={appointments} defaultCurrentDate={new Date(2016, 4, 25)} /> <Button text="Update" onClick={updateAppointment} /> </React.Fragment> ); } } export default App;
Events
To execute certain commands before or after an appointment was updated, handle the appointmentUpdating or appointmentUpdated 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.
jQuery
$(function () { $("#schedulerContainer").dxScheduler({ // ... onAppointmentUpdating: function (e) { // Handler of the "appointmentUpdating" event }, onAppointmentUpdated: function (e) { // Handler of the "appointmentUpdated" event } }); });
Angular
<dx-scheduler ... (onAppointmentUpdating)="onAppointmentUpdating($event)" (onAppointmentUpdated)="onAppointmentUpdated($event)"> </dx-scheduler>
import { DxSchedulerModule } from "devextreme-angular"; // ... export class AppComponent { onAppointmentUpdating (e) { // Handler of the "appointmentUpdating" event } onAppointmentUpdated (e) { // Handler of the "appointmentUpdated" event } } @NgModule({ imports: [ // ... DxSchedulerModule ], // ... })
Vue
<template> <DxScheduler ... @appointment-updating="onAppointmentUpdating" @appointment-updated="onAppointmentUpdated" /> </template> <script> import 'devextreme/dist/css/dx.light.css'; import DxScheduler from 'devextreme-vue/scheduler'; export default { components: { DxScheduler }, data() { return { // ... }, methods: { onAppointmentUpdating: (e) => { // Handler of the "appointmentUpdating" event }, onAppointmentUpdated: (e) => { // Handler of the "appointmentUpdated" event } } } } </script>
React
import React from 'react'; import 'devextreme/dist/css/dx.light.css'; import Scheduler from 'devextreme-react/scheduler'; const onAppointmentUpdating = (e) => { // Handler of the "appointmentUpdating" event } const onAppointmentUpdated = (e) => { // Handler of the "appointmentUpdated" event } class App extends React.Component { render() { return ( <Scheduler ... onAppointmentUpdating={onAppointmentUpdating} onAppointmentUpdated={onAppointmentUpdated} /> ); } } export default App;
jQuery
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 events using the on(eventName, eventHandler) method.
var updatedEventHandler1 = function (e) { // First handler of the "updated" event }; var updatedEventHandler2 = function (e) { // Second handler of the "updated" event }; $("#schedulerContainer").dxScheduler("instance") .on("appointmentUpdated", updatedEventHandler1) .on("appointmentUpdated", updatedEventHandler2);