DataSource cancelChanges not reflected in UI

16 posts, 0 answers
  1. Jaap
    Jaap avatar
    96 posts
    Member since:
    Oct 2012

    Posted 13 Apr 2012 Link to this post

    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
  2. Rosen
    Admin
    Rosen avatar
    3237 posts

    Posted 17 Apr 2012 Link to this post

    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!
  3. Kendo UI is VS 2017 Ready
  4. Dennis
    Dennis avatar
    30 posts
    Member since:
    Aug 2012

    Posted 28 Aug 2012 Link to this post

    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?
  5. Dennis
    Dennis avatar
    30 posts
    Member since:
    Aug 2012

    Posted 28 Aug 2012 Link to this post

    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.
  6. Joshua
    Joshua avatar
    66 posts
    Member since:
    May 2012

    Posted 13 Nov 2012 Link to this post

    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...
  7. Yavuz
    Yavuz avatar
    2 posts
    Member since:
    Feb 2012

    Posted 10 May 2013 Link to this post

    Rosen, you wrote "you can raise the change event" but didn't explain how.  How can I raise the change event?
  8. Rosen
    Admin
    Rosen avatar
    3237 posts

    Posted 13 May 2013 Link to this post

    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!
  9. Marcel
    Marcel avatar
    36 posts
    Member since:
    Apr 2011

    Posted 25 Sep 2013 Link to this post

    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 ?
  10. Rosen
    Admin
    Rosen avatar
    3237 posts

    Posted 26 Sep 2013 Link to this post

    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!
  11. Marcel
    Marcel avatar
    36 posts
    Member since:
    Apr 2011

    Posted 26 Sep 2013 Link to this post

    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).
  12. Will
    Will avatar
    34 posts
    Member since:
    Oct 2013

    Posted 26 Mar 2014 Link to this post

    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();
            }



     
  13. Bilal
    Bilal avatar
    109 posts
    Member since:
    Oct 2014

    Posted 16 Feb 2015 in reply to Rosen Link to this post

    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
  14. Rosen
    Admin
    Rosen avatar
    3237 posts

    Posted 16 Feb 2015 Link to this post

    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!
     
  15. Bilal
    Bilal avatar
    109 posts
    Member since:
    Oct 2014

    Posted 16 Feb 2015 in reply to Rosen Link to this post

    Thanks Rosen. Is this documented somewhere?

    Regards
    Bilal
  16. Rosen
    Admin
    Rosen avatar
    3237 posts

    Posted 18 Feb 2015 Link to this post

    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!
     
  17. Bilal
    Bilal avatar
    109 posts
    Member since:
    Oct 2014

    Posted 18 Feb 2015 in reply to Rosen Link to this post

    Thanks!
Back to Top
Kendo UI is VS 2017 Ready