Greg
Greg

Reputation: 2690

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
                     }
                    ]
 }
]

Upvotes: 13

Views: 17682

Answers (1)

dan
dan

Reputation: 2957

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"
},

Upvotes: 13

Related Questions