Adding/Deleting Events

Adding events

To add an event to the scheduler, you may use one of three methods:

  1. addEvent - adds a new event and invokes the onEventAdded or onEventChanged event;
  2. addEventNow - adds a new event and opens the lightbox to confirm. Doesn't invoke any events;
  3. setEvent - adds a new event to the scheduler's data pool. Doesn't invoke any events.

The most recommended way is the addEvent method:

var eventId = scheduler.addEvent({
    start_date: "16-06-2019 09:00",
    end_date:   "16-06-2019 12:00",
    text:   "Meeting",
    holder: "John",  // user data
    room:   "5"      // user data
});

Related sample:  Validating lightbox fields

Related sample:  Default values for lightbox controls

Updating events

There are two cases of updating events possible in Scheduler:

  1. if you need just to re-render the event without sending changes to the server, use updateEvent
  2. if you need to apply and save changes on the server - it's better to choose the addEvent method
var eventId = scheduler.addEvent({
    start_date: "16-06-2019 09:00",
    end_date:   "16-06-2019 12:00",
    text:   "Meeting"
});
 
var event = scheduler.getEvent(eventId);
event.text = "Conference"; //changes event's data
 
scheduler.updateEvent(event.id); // repaint without sending to the server
//or
scheduler.addEvent(event.id); // repaint and send update to the server

Deleting events

To delete an existing event from the scheduler, use the deleteEvent method:

scheduler.parse([
   {id:1, start_date:"06/30/2009 09:00", end_date:"06/30/2009 12:00", text:"Task1"},
   {id:2, start_date:"06/30/2009 12:00", end_date:"06/30/2009 20:00", text:"Task2"}
],"json");
...
scheduler.deleteEvent(2);

If you have dataProcessor initialized, added to/deleted from the scheduler events will be automatically added/deleted in the data source. See the detailed information in the Server-Side Integration guide.

Related sample:  Fully custom lightbox

Back to top