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

DataSource wont detect changes with MVVM after read second time.

1 Answer 89 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
florim
Top achievements
Rank 1
florim asked on 13 Aug 2013, 07:04 PM
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(dataItem.id);
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
ds.read();//hear i need to have the latest data so i do a read from db
var dr2 = ds.get(this.selectedItem.id);//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  
           ds.sync(); 
        }


this issue is when in function changeMode i use ds.read(), if i remove it it works

1 Answer, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 15 Aug 2013, 09:06 AM
Hello Florim,

When you use ds.read(), 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 ds.read(), so no changes are lost.
 
Regards,
Kiril Nikolov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Data Source
Asked by
florim
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
Share this question
or