How to update a model in an existing data source?

6 posts, 0 answers
  1. Jonathan
    Jonathan avatar
    57 posts
    Member since:
    Jun 2012

    Posted 22 May 2012 Link to this post

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


  2. Rosen
    Admin
    Rosen avatar
    3237 posts

    Posted 23 May 2012 Link to this post

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

    Posted 23 May 2012 Link to this post

    Thanks Rosen, nice piece of information.

    -------------------
  5. Jonathan
    Jonathan avatar
    57 posts
    Member since:
    Jun 2012

    Posted 23 May 2012 Link to this post

    Is there a way I can replace the entire entity?
  6. Rosen
    Admin
    Rosen avatar
    3237 posts

    Posted 23 May 2012 Link to this post

    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!
  7. John
    John avatar
    1 posts
    Member since:
    May 2012

    Posted 23 May 2012 Link to this post

    Thanks
Back to Top
Kendo UI is VS 2017 Ready