React Scheduler - Update Appointments

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.

  • 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.

  • 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.

App.js
  • 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.

App.js
  • 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;
See Also