kendo-uikendo-mvvm

Kendo MVVM Cancel Changes to ObservableObject


I'm new to Kendo, is there a cancelChanges like method similar to Kendo DataSouce on ObservableObject and ObservableArray? https://docs.telerik.com/kendo-ui/api/javascript/data/datasource/methods/cancelchanges

I bind the view to ObservableObject using data-bind="source: Products", where products is an ObservableObject. I would like to provide a cancel function (bind to 'close' button on view) in this ObservableObject which when clicked must cancel the changes.

Products = kendo.observable({

cancel: function(e) {...}   //undo changes here...

});

Solution

  • No, there is no such mechanism built in. Kendo does not track the changes made so you will need to do it yourself. The simplest approach is to take a copy of Products, or the data that it contains, at the beginning. To revert any changes you would then set Products, or the data within, back to the copy you took at the start. If you 'save' changes, update the copy so that the user can make further changes and then cancel back to the last point they 'saved'.