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

Working with the returned Data from "fetch" Method

6 Answers 274 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
mgs
Top achievements
Rank 1
mgs asked on 03 Mar 2013, 05:26 PM
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

6 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 06 Mar 2013, 08:55 AM
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!
0
mgs
Top achievements
Rank 1
answered on 06 Mar 2013, 11:05 AM
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

0
Petur Subev
Telerik team
answered on 08 Mar 2013, 08:17 AM
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!
0
mgs
Top achievements
Rank 1
answered on 08 Mar 2013, 08:54 AM
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
0
Petur Subev
Telerik team
answered on 11 Mar 2013, 07:53 AM
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!
0
mgs
Top achievements
Rank 1
answered on 11 Mar 2013, 10:16 AM
Hello Peter,

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

Michael G. Schneider
Tags
Data Source
Asked by
mgs
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
mgs
Top achievements
Rank 1
Share this question
or