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

How to update a model in an existing data source?

5 Answers 472 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 22 May 2012, 07:08 PM
How do I update a piece of data in an existing dataset? The following is the code I have for updating and adding to an existing dataset, the add works correctly, but how do I make the update work?

function AddEntityToDataSource(entityset, entity) {
 
    var ds = GetDataSource(entityset);
 
    ds.add(entity);   
     
}
 
function UpdateEntityToDataSource(entityset, entity) {
 
    var ds = GetDataSource(entityset);
 
    entity = ds.get(entity.id);
 
}


5 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 23 May 2012, 08:46 AM
Hi Jonathan,

In order to modify field values of a Model instance you should use its set method:

entity = ds.get(entity.id);
entity.set("foo", "bar"); // set foo field value to be bar

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
Mitchell
Top achievements
Rank 1
answered on 23 May 2012, 11:46 AM
Thanks Rosen, nice piece of information.

-------------------
0
Jonathan
Top achievements
Rank 1
answered on 23 May 2012, 03:47 PM
Is there a way I can replace the entire entity?
0
Rosen
Telerik team
answered on 23 May 2012, 03:58 PM
Hi Jonathan,

I'm afraid this is not supported.

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
John
Top achievements
Rank 1
answered on 23 May 2012, 06:27 PM
Thanks
Tags
Data Source
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Mitchell
Top achievements
Rank 1
Jonathan
Top achievements
Rank 1
John
Top achievements
Rank 1
Share this question
or