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

DataSource cancelChanges not reflected in UI

15 Answers 417 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Jaap
Top achievements
Rank 2
Jaap asked on 13 Apr 2012, 01:36 PM
I have a DataSource with one model/record in it and I have binded that to some input controls:
kendo.bind($(....), _myDataSource.view()[0]);

When I want to cancel the changes (when e.g. the user chooses "Cancel") I call _myDataSource.cancelChanges().
I then see that the model in de datasource is reverted.
But the bindings are not updated, so still the modified values are visible.

Any idea?

Regards, Jaap

15 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 17 Apr 2012, 02:49 PM
Hello Jaap,

Indeed, due to performance reasons, the change notification of the model will not be triggered when the DataSource data is reverted to its original state. However, you may use the DataSource's change event to  manually repopulate the form.

All the best,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Dennis
Top achievements
Rank 1
answered on 28 Aug 2012, 04:14 PM
Hi, I have the exact same issue now. Did anybody manage to make a different solution. Sorry but manualy repopulating the form just seems to go against  everything mvvm stands for and I find it a terrible solution. Isnt there a better way to trigger the model change event?
0
Dennis
Top achievements
Rank 1
answered on 28 Aug 2012, 04:19 PM
I also think this is a very common scenario, and again one that doesn't exist in the demos or any of the documentaiton. The expected behavior for most users is that the model gets normally updated after the cancelChanges, but the only way for them to find out that this is not the case is by digging in the forums. Thats just plain terrible. I don't mean to hate with this. I love Kendo. Just trying to give some constructive feedback.
0
Joshua
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 13 Nov 2012, 10:27 PM
has any movement been made on this?

When i populate a grid from a datasource that has been bound to a local array and then tell my datasource to cancel changes, then it just clears all of the rows from my grid...
0
Yavuz
Top achievements
Rank 1
answered on 10 May 2013, 02:49 PM
Rosen, you wrote "you can raise the change event" but didn't explain how.  How can I raise the change event?
0
Rosen
Telerik team
answered on 13 May 2013, 06:46 AM
Hi Yavuz,

I'm afraid that I did not mentioned anything about triggering the change event manually. The suggestion was to use the DataSource change event, which will be triggered automatically when cancelChanges() is called, and in the event handler to update the form by hand.

Regards,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Marcel
Top achievements
Rank 1
answered on 25 Sep 2013, 09:33 AM
I'm using the Datasource bound to a Grid and have the same problem when I call cancelChanges and pass in a model to cancel the changes for. The UI is not updated so the grid row shows the values from before the cancelChanges.

I understood this is by design due to performance issues, but it isn't expected behavior at all.
End-users get confused thinking they didn't cancel at all and it leads to strange side-effects.

Is there any other way to accomplish re-binding or change notification to the bound elements of the model ?
0
Rosen
Telerik team
answered on 26 Sep 2013, 07:27 AM
Hello Marcel,

From the description you have provided it seems that you are calling the DataSource cancelChanges from some external code. Therefore, you will need to manually refresh the Grid UI via its refresh method. Similar to the following:

function cancel(model) { 
  var grid = $("#grid").data("kendoGrid");
  var dataSource = grid.dataSource;
   
  dataSource.cancelChanges(model);
  grid.refresh();
}

Regards,
Rosen
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Marcel
Top achievements
Rank 1
answered on 26 Sep 2013, 07:57 AM
The grid.refresh() after cancelChanges(model) works, but leads to strange side-effects in the grid when the grid is set to paging with virtual scrolling.  I already made a post for that in the grid section here.
When i'm on another page then the first the whole row disappears after cancelChanges(model).
0
Will
Top achievements
Rank 1
answered on 26 Mar 2014, 01:54 PM
This is an old thread but for those stumbling through it now as I am, here's another solution.  Part of the difficulty is that there seem to be many different ways of doing everything in Kendo UI.

Based on some of the examples out there I ended up using the technique of assigning the content of the first item of the DataSource's collection to my own ViewModel defined object, 'carrier' in the DataSource's change event handler the first time it is called. 

change: function (e) {
    var isFirstTime = carrierViewModel.get("firstTime");
 
    if (isFirstTime) {
        carrierViewModel.set("firstTime", false);
        carrierViewModel.set("carrier", this.data()[0]);
        kendo.bind(kendoContainer, carrierViewModel);
        .
        .
        .


This is what I do my data-bind to e.g. data-bind="value: carrier.someFieldName" instead of the clunkier data-bind="value: carrierDS.data()[0].someFieldName". 

In my ViewModel's 'cancel' event handler, I just reload the ViewModel's 'carrier' object from the DataSource again since they are not kept in sync.  I call the DataSource's cancelChanges() method but I don't believe that it is doing anything useful.

cancel: function () {
            this.carrierDS.cancelChanges();
            this.set("carrier", this.carrierDS.data()[0]);
            validator.hideMessages();
        }



 
0
Bilal
Top achievements
Rank 2
answered on 16 Feb 2015, 02:57 PM
Hello Rosen,

I had the same problem discussed in this thread.

I noticed that when I call dataSource.cancelChanges and supplying a model, the change event of the Data Source is not fired. While, cancelChanges without any model, the change event does fire. 

Any idea?
Thanks
0
Rosen
Telerik team
answered on 16 Feb 2015, 04:12 PM
Hi Bilal,

Indeed, this is the designed behavior of cancelChanges method. The change event of the DataSource will be triggered only when all of the changes are reverted. It will not be triggered when cancelChanges method is called for particular model instance.  

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Bilal
Top achievements
Rank 2
answered on 16 Feb 2015, 06:58 PM
Thanks Rosen. Is this documented somewhere?

Regards
Bilal
0
Rosen
Telerik team
answered on 18 Feb 2015, 09:00 AM
Hello Bilal,

Although, it is not currently mentioned in the documentation, we will consider adding it.

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Bilal
Top achievements
Rank 2
answered on 18 Feb 2015, 09:21 AM
Thanks!
Tags
MVVM
Asked by
Jaap
Top achievements
Rank 2
Answers by
Rosen
Telerik team
Dennis
Top achievements
Rank 1
Joshua
Top achievements
Rank 2
Iron
Veteran
Iron
Yavuz
Top achievements
Rank 1
Marcel
Top achievements
Rank 1
Will
Top achievements
Rank 1
Bilal
Top achievements
Rank 2
Share this question
or