How to "Undo" event changes?

Hello,
In my project I am using local data as dataSource. Also, I am manually storing schedule data in DB server using api calls on "eventCreate" and "eventChange" action request type .


When I create/update an event, local data is reflecting the changes. But i need to undo those changes if API responds with errors. How to do that programmatically?


Regards,
Sk. Azadur Rahman


3 Replies 1 reply marked as answer

RV Ravikumar Venkatesan Syncfusion Team August 24, 2022 12:13 PM UTC

Hi Sk Azadur Rahman,


Greetings from Syncfusion support.


We have validated your query “I need to undo those changes if API responds with errors. How to do that programmatically?” at our end. We suggest you set the args.cancel as true in the actionBegin event of the Schedule as shown in the below code snippet and update the Schedule data source once the data is successfully updated at the server end.


[index.js]

  onActionBegin(args) {

    // Cancel the CRUD action by setting up args.cancel = true

    args.cancel = ['eventCreate''eventChange''eventRemove'].indexOf(args.requestType) > -1;

    if (args.requestType === 'eventCreate') {

      const ajax = new Ajax('http://localhost:54738/Home/Insert''POST'false);

      ajax.data = JSON.stringify(args.data[0]);

      ajax.onSuccess = (data=> {

        // The added appointment was updated to the server the whole appointment collection was received from the server and we are updating the collection to the Schedule data source

        this.updateScheduleData(data);

      };

      ajax.send();

    } else if (args.requestType === 'eventChange') {

      const ajax = new Ajax('http://localhost:54738/Home/Update''POST'false);

      ajax.data = JSON.stringify(args.data);

      ajax.onSuccess = (data=> {

        // The changed appointment was updated to the server the whole appointment collection was received from the server and we are updating the collection to the Schedule data source

        this.updateScheduleData(data);

      };

      ajax.send();

    } else if (args.requestType === 'eventRemove') {

      const ajax = new Ajax('http://localhost:54738/Home/Delete''POST'false);

      ajax.data = JSON.stringify(args.data[0]);

      ajax.onSuccess = (data=> {

        // The removed appointment was deleted from the server the whole appointment collection was received from the server and we are updating the collection to the Schedule data source

        this.updateScheduleData(data);

      };

      ajax.send();

    }

  }

 

  updateScheduleData(data) {

    this.scheduleObj.eventSettings.dataSource = JSON.parse(data);

    this.scheduleObj.dataBind();

  }


Kindly let us know if you need any further assistance on this.


API: https://ej2.syncfusion.com/react/documentation/api/schedule/#actionbegin


Regards,

Ravikumar Venkatesan


Marked as answer

SA Sk Azadur Rahman August 25, 2022 07:15 PM UTC

Hi Ravikumar,

Thanks for the solution. Idea of dataBind() works perfectly.

Regards,

Sk. Azadur Rahman



RV Ravikumar Venkatesan Syncfusion Team August 26, 2022 04:52 AM UTC

Hi Sk Azadur Rahman,


Thanks for the update.


We are happy that our solution works for you.


Regards,

Ravikumar Venkatesan


Loader.
Up arrow icon