DataSource wont detect changes with MVVM after read second time.

2 posts, 0 answers
  1. florim
    florim avatar
    1 posts
    Member since:
    Aug 2007

    Posted 13 Aug 2013 Link to this post

    I have a view where i have autocomplete with datasource (ds) where user can search (for person) and when it select in select function for autocomplete i have
    select: function (sel) {
    var dataItem = this.dataItem(sel.item.index());
    var md = ds.get(;
    model.selectContact(md);//set the observable

    then in my viewModel i have a method where i fill observable property
    selectContact: function (cust) {
    this.set('selectedItem', cust);//this is a observable property

     when user click edit in my ViewModel a call this method
    changeMode:function() {//ds is the kendoDataSource;//hear i need to have the latest data so i do a read from db
    var dr2 = ds.get(;//get last id from datasource that it was selected in autocomplete
    this.set('selectedItem', dr2);//now hear is the latest data in observable property

    then user change the fields (example name) in a view and when it hits Save 
     save: function () {
                alert(ds.hasChanges());// this returns false even if i look to the this.selectedItem and i see that binding is pushet to the observable property  

    this issue is when in function changeMode i use, if i remove it it works

  2. Kiril Nikolov
    Kiril Nikolov avatar
    2598 posts

    Posted 15 Aug 2013 Link to this post

    Hello Florim,

    When you use, the DataSource is updated with the latest data read from the database, so all the changes made prior to that and that are omitted. Furthermore nowhere in your code could be found how you update the data item in the DataSource? The this.set('selectedItem', dr2) declaration, updates the ViewModel, but not the DataSource.

    I would also suggest you to check for changes before the, so no changes are lost.
    Kiril Nikolov
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top