Working with the returned Data from "fetch" Method

7 posts, 0 answers
  1. mgs
    mgs avatar
    163 posts
    Member since:
    Jan 2011

    Posted 03 Mar 2013 Link to this post

    The documentation for the Datasource http://docs.kendoui.com/api/framework/datasource  tells about the returned object of the "at" method.
    kendo.data.ObservableObject | kendo.data.Model The type depends on the schema.
    Would you please explain that a little bit. When ObservableObject? When Model?

    In my sample, there is a model and a datasource (transport and several other parts ommited). Some data is read from a remote server.
    var model = kendo.data.Model.define({
       id: "ID",
       fields: {
          ID: { type: "number", editable: false },
          Name: { type: "string", validation: { required: true } }
       }
    });
     
    var datasource = {
       schema: {
          model: model
       }
    };
     
    var ds = new kendo.data.DataSource(datasource);
    ds.fetch(function () {
       var data = ds.at(0);
    });
    Now, what is given back from the "at" method? Is it an ObservableObject? Does it have a reference to the model?

    Looking at "data" when debugging makes me think that it does have a connection to the model, as the "fields" collection is part of the object. However, if "data" is bound to some HTML View, the model seems to be ignored. The "editable" is not regarded on input, the "required" is not regarded on validation.

    Michael G. Schneider
  2. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 06 Mar 2013 Link to this post

    Hello Michael,

    Basically the Model extends the ObservableObject type as explained in the documentation. 

    http://docs.kendoui.com/api/framework/model

    So when declaring your dataSource if you have specified schema.model - the instances of the dataSource.data() will be models. If you have not declared model they will be ObservableObjects.

    You can play with the following fiddle to see the answers in action:

    http://jsbin.com/edamuj/510/edit

    Remove the schema definition and see the difference when you click the test button.


    Kind Regards,
    Petur Subev
    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. mgs
    mgs avatar
    163 posts
    Member since:
    Jan 2011

    Posted 06 Mar 2013 Link to this post

    Hello Peter,

    thanks a lot for the answer. Regarding "when Model, when ObservableObject", this is understood now.

    However, how about the last part of my question? If the model is indeed part of the datasource's data, why isn't this model applied when it is bound to some HTML?

    Please look at the fiddle. Why is the input for the ID editable?

    I do know that I can edit the HTML for making the ID readonly. However, if this is necessary, then all information from the model has to be manually carried over to the HTML.

    Michael G. Schneider

  5. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 08 Mar 2013 Link to this post

    Hello again Michael,

    Thank you for writing back.

    Actually when you set editable to false it means that the model wont be updaded by the MVVM - it does not make the fields bound to it readonly.

    I modified the example you shared to demonstrate this.

    http://jsfiddle.net/8hkrV/4/

    I am sure you will get the idea.

    Best Regards,
    Petur Subev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  6. mgs
    mgs avatar
    163 posts
    Member since:
    Jan 2011

    Posted 08 Mar 2013 Link to this post

    Hello Peter,

    thanks a lot for the answer. I do understand your explanation, And I also understand that I have to modify the HTML for making the input element readonly.

    However, I think this situation might be improved. Wouldn't it be good, if "kendo.bind" applied all information from the model to the HTML elements? That way all settings like editable, validation, required, min, max, etc. would only be necessary in one central place.

    Michael G. Schneider
  7. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 11 Mar 2013 Link to this post

    Hello again Michael,

    Thank you for the feedback, I see what you mean and since you are the first one who requires such feature I would suggest you to share your idea on our Kendo User Voice page where more people can vote for it.
    If it gains popularity our team will consider if such improvement can be successfully added to the MVVM framework.

    http://feedback.kendoui.com/forums/127393-kendo-ui-feedback

    Kind regards,
    Petur Subev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  8. mgs
    mgs avatar
    163 posts
    Member since:
    Jan 2011

    Posted 11 Mar 2013 Link to this post

    Hello Peter,

    thanks a lot for the answer. Here is a link to the User Voice Item.

    Michael G. Schneider
Back to Top
Kendo UI is VS 2017 Ready