Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What must my Kendo datasource schema look like?

given this json?

[
 { 
  "CompanyId":20,
  "CompanyName":"Walmart",
  "CompanyContacts":[
                     {
                      "CompanyId":20,
                      "FirstName":"Bob",
                      "LastName":"Green",
                      "Email":"[email protected]",
                      "Phone":"1234567",
                      "IsActive":false
                     }
                    ]
 }
]
like image 496
Greg Avatar asked Feb 06 '13 14:02

Greg


People also ask

What is schema in kendo grid?

schema ObjectThe configuration used to parse the remote service response.

What is Kendo data DataSource?

The Kendo UI DataSource component plays a central role in all web applications built with Kendo UI for jQuery. The DataSource is an abstraction for using local data (arrays of JavaScript objects) or remote data (web services returning JSON, JSONP, oData, or XML).


1 Answers

The KendoUI datasource schema.Model does not currently support nested json or json with related entities. It needs flat data. Hopefully in the future the schema.Model will support mapping complex json to flat in the model definition. However you can still use complex data in the grid you just can't define it in a schema.Model definition.

The mapping is actually done in the field definitions of the grid. In addition see schema docs you can parse your data using the schema.parse or schema.data functions to manually transform your nested data into flat data.

Here is a fiddle example with your data

{
    field : "CompanyContacts[0].FirstName",
    title: "First Name"
}

Also note, if you don't need parent record CompanyName and CompanyID since you have CompanyID in your CompanyContacts in the way your data is currently defined then you can use the data attribute of the schema to indicate the starting point of your records like so

schema : {
    model: mySchema,
    data: "CompanyContacts"
},
like image 200
dan Avatar answered Oct 09 '22 06:10

dan