Create remote event with Scheduler and Datamanager

Hello,

It's been a few days that i'm trying to create an event on a scheduler using a webApiAdaptor and a grails backend.

On the frontend part, I have my scheduler, which is retrieving and displaying events fine.

It is declared this way :


var dataManager = new ej.data.DataManager({
url: getContextPath() + '/agenda/events',
insertUrl: getContextPath() + '/agenda/create',
removeUrl: getContextPath() + '/agenda/delete',
updateUrl: getContextPath() + '/agenda/edit',
adaptor: new ej.data.WebApiAdaptor(),
crossDomain: true
});

var scheduleObj = new ej.schedule.Schedule({
// init code …

eventSettings: {
dataSource: dataManager
}

});
scheduleObj.appendTo('#Schedule');

I've added an eventListener on actionBegin and eventCreate to try to post something to my backend :

scheduleObj.addEventListener('actionBegin', function (args) {
if (args.requestType === 'eventCreate') {
alert('event creation');
// THIS IS FOR TEST PURPOSE dataManager.requestType = "POST"
dataManager.executeQuery(new ej.data.Query().addParams("Event", JSON.stringify(args.addedRecords[0])))
.then((e) => {
dataManager = e.result
});
}
});

The goal here is to send a post request to dataManager.insertUrl. This way doesn't work : the schedule component is sending a get request to dataManager.url.

If I change dataManager.url to the correct url (aka /agenda/create), my backend get the event and a JSON response is returned, with Items: ​and Count:​ fields, but I get an actionFailure error on the frontend, and the schedule is not refreshed with the newly created appointment.

What is my mistake, and how to correct it ?


Final goal is to send the created appointment in the schedule component to the backend and save it to some DB


Thanks


5 Replies

BS Balasubramanian Sattanathan Syncfusion Team February 24, 2022 05:11 PM UTC

Hi Masao,

We suspect that your need is to have the Scheduler CRUD actions with backend service. For that, we would suggest you to use the URL adaptor to have it. 

UG: https://ej2.syncfusion.com/javascript/documentation/schedule/data-binding/#scheduler-crud-actions

Service: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ScheduleCRUD_Service-1718435969.zip
Sample: https://stackblitz.com/edit/oppcct-yjjywa?file=index.js

Note: You need to run the service project first to have the appointment in the Scheduler

Kindly refer to the above links and let us know if you need further assistance.

Regards,
Balasubramanian S



MA Masao February 28, 2022 07:58 PM UTC

Hi, thanks for the answer.


I've already read the documentation, and to be honest, I didn't find my answers :)


I've managed to resolve my problem of creating/deleting/updating data, with a WebApiAdaptor, but now i'm stock with the refreshing part, which is very long.

I actually use scheduleObj.refresh(), because updating the datamanager with the list of event does'nt do anything, but it do a new request that is time consuming.


Is there any other way to refresh data displayed by the scheduler component ?


Tham



BS Balasubramanian Sattanathan Syncfusion Team March 1, 2022 10:52 AM UTC

We let you know that the scheduler events can be refreshed by using the refreshEvent public method. Can you please try this method and let us know whether it fulfilled your requirement or not?

UG: https://ej2.syncfusion.com/javascript/documentation/schedule/appointments/#refresh-appointments



MA Masao March 1, 2022 04:09 PM UTC

Hello,


Thanks for that answer. I'm already using it, but refreshEvents() makes a new request to refresh, which is quite long and I'm trying to avoid that.

It seems crazy that the scheduler doesn't refresh with the appropriate json answer :

{Items: {blablablab…}, Count: XX }





BS Balasubramanian Sattanathan Syncfusion Team March 2, 2022 03:49 PM UTC

We let you know that all the appointments will be refreshed when we use refreshEvents method. You can load the appropriate appointments(current view date-range) by using the StartDate and EndDate by using the below code snippet on the server side.

HomeController.cs:

// Here we get the Start and End Date and based on that can filter the data and return to Scheduler
public
 JsonResult LoadData(Params param) 

{

    // Here filtering the events based on the start and end date value. 

    var data = db.ScheduleEventDatas.Where(app => (app.StartTime >= param.StartDate && app.StartTime <= param.EndDate) || (app.RecurrenceRule != null && app.RecurrenceRule != "")).ToList();

    return Json(data, JsonRequestBehavior.AllowGet);

}



Loader.
Up arrow icon