This is a migrated thread and some comments may be shown as answers.

Update CRUD operation being triggered when 'Cancel' is pressed in event edit

3 Answers 182 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Tyler
Top achievements
Rank 1
Tyler asked on 20 Mar 2017, 02:45 PM

My cancel event in my scheduler is like so:

 

cancel: function(e){
                                console.log('Cancelling');
                            console.log(e); 
                                console.log(e.event.ownerId[0].value);
                                console.log(e);
                                if(e.event.id != '0'){
                                    e.sender.dataSource.sync();
                                    //e.sender.dataSource.read();
                                }
                            },

 

The only way I was able to get the scheduler to work somewhat properly is by calling dataSource sync in the cancel method because  before doing that, if you pressed cancel, the data structure of the event was altered and if you tried to re-open that event, it threw an error with my kendo multi-selects inside the edit/create window. However, by calling sync, the scheduler refreshes its data when you cancel and it all goes back to the way it should be.

My issue though... is that when I press cancel and it does its sync, it triggers the update method. So it basically has the same functionality as the save event because it goes through update and alters the data of the event if anything was changed and doesn't actually 'cancel'

I am wondering how I might prevent it from running update when cancel is pressed? And what determines if update CRUD operation is ran? Like I know that create gets triggered when the ID of the event is the default id specified in the schema, but not sure what determines if update should go or not. Is that the dirty bit of the event?

3 Answers, 1 is accepted

Sort by
0
Ianko
Telerik team
answered on 22 Mar 2017, 08:03 AM

Hello Tyler,

It is the sync method called that triggers the update. And this is expected as sync will update all changes. Doing that during the cancel event is expected to actually update the data as the values are not changing and calling sync updates them. Further on, logic is not capable of reverting changes as they are already updated. And fields marked as dirty are cleared. 

I am not sure why the sync method should be used in first place. Cancel button should operate properly and cancel any updates done to the event. At least this is what happens when testing in this demo: http://demos.telerik.com/kendo-ui/scheduler/index

If, however, you have some fields that are being updated programmatically and the end user has no access of this to cancel you can rather use the cancelChanges method of the DataSoucre.

Regards,
Ianko
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Tyler
Top achievements
Rank 1
answered on 23 Mar 2017, 03:29 PM

I am utilizing dataSource.sync() in my cancel event on the scheduler because when opening up the event in the edit menu, values for my owner actually changes from an ID to an object due to my use of a multi-select box for the owner, so If I hit cancel, the event keeps the changes it made and the owner is lost because it is an object (with the correct owner's info) but not their ID, which is what I need. So calling sync refreshes the scheduler and reverts the events back to original format so owner is kept as it was with just the ID. The issue is, of course, that sync calls update... so even though I am pressing cancel, any changes made actually get saved.

I suppose a simple solution would be utilize a flag, and just don't execute anything in the update method if flag is set and set the flag inside the cancel event...

0
Ianko
Telerik team
answered on 24 Mar 2017, 07:18 AM

Hello Tyler,

In your case, perhaps the solution with the flag would be appropriate. 

If, however, you have further difficulties on the topic demonstrate the situation in a dojo (http://dojo.telerik.com/) so that I could properly take a look at the situation with the MultiSelect used.

Regards,
Ianko
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Scheduler
Asked by
Tyler
Top achievements
Rank 1
Answers by
Ianko
Telerik team
Tyler
Top achievements
Rank 1
Share this question
or