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

How can I read the expand Entity using Kendo UI Datasource Schema?

3 Answers 116 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
DG
Top achievements
Rank 1
DG asked on 08 May 2014, 04:34 PM
I am trying to read the Entity1 using the dataSource schema from the returned json object.


The Json Object is as follow
{
"odata.metadata":"http://localhost:25061/odata/$metadata#Entity,"value":[
{
"Entity1":{
"LastName":"Smith","FirstName":"James"},"Id":1,"Other":2},{
"Entity1":{
"LastName":"Smith","FirstName":"Alex"},"Id":2,"Other":3}
}]
}Datasource Schema
schema: {
data: function (data) { return data.value; },
total: function (data) { return data["odata.count"]; },
},Model
$("#grid").kendoGrid({
dataSource: dataSource,
filterable: true,
sortable: true,
pageable: true,
columns: [
{ field: "LastName" },
{ field: "FirstName" }
]
});Thanks,
DG

3 Answers, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 12 May 2014, 03:26 PM
Hello Douglas,

The data that the grid will use for its dataSource must contain an array of objects. In the schema.data property you can set the path to this array of objects that will hold the information that will be shown in the Grid. The sample that that you showed is invalid JSON (according to jsonlint.com).

I have tried to recreate a simple example with a data similar to yours here:

http://jsbin.com/kelon/1/edit

You can use this example as a reference, or if it does not help, please edit it so it can show your exact scenario and we will be happy to assist you further.

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
DG
Top achievements
Rank 1
answered on 12 May 2014, 05:46 PM
Hi Kiril,
Sorry for the invalid Json
Below you'll find the valid Json as a result of the expand call
http://localhost:25061/odata/ParentEntity?$filter=ParentEntityIdField%20eq%2057%20&$inlinecount=allpages&$expand=ChildexpandedEntity&$top=3
{
  "odata.metadata":"http://localhost:port/odata/$metadata#ParentEntity","odata.count":"5560","value":[
    {
      "ChildexpandedEntity":{
        "ChildexpandedEntityId":1,"ChildexpandedEntityLastName":"Smith1"
      },"ParentEntityId":1
    },{
      "ChildexpandedEntity":{
        "ChildexpandedEntityId":1,"ChildexpandedEntityLastName":"Smith2"
      },"ParentEntityId":2
    },{
      "ChildexpandedEntity":{
        "ChildexpandedEntityId":1,"ChildexpandedEntityLastName":"Smith3"
      },"ParentEntityId":2
    }
  ]
}




0
Kiril Nikolov
Telerik team
answered on 13 May 2014, 11:46 AM
Hi Douglas,

In your case you will need to parse the response in order to display it correctly inside the Kendo UI Grid. Here is a sample that I created:

http://jsbin.com/kelon/2/edit

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
DG
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
DG
Top achievements
Rank 1
Share this question
or