Kendo UI Grid - How to Bind to Child Properties -
how bind column/field kid property of json result in model settings of kendo grid (in javascript)? example, want grid contain columns: fname, lname, street , address. want flatten hierarchical construction returned web service.
kendo settings
fields: { fname: { type: "string" }, lname: { type: "string" }, // how map kid properties below? street: { field: "address.street" }, // wrong city: { field: "address.city" } // wrong }
json
{ "fname": "william", "lname ": "shakespeare", "address": { "address": "123 street ln", "city": "philadelphia" } }
you don't that. need create class 'model' flattens info graph. able utilize lazy loading during construction of model. either send model view via controller or attach larger viewmodel (just model of models not mvvm) sent view. bind grid.
but, happier utilize ajax loading of same model json, think trying do.
model
public class contactmodel { public string fname { get; set; } public string lname { get; set; } public string address { get; set; } public string city { get; set; } public contactmodel() {} public contactmodel(contact contact) // icontact improve if have interfaces { fname = contact.fname; lname = contact.lname; address = contact.address.address; city = contact.address.city; } // neat linq trick convert database query results straight model public static ilist<contactmodel> flattentothis(ilist<contact> contacts) { homecoming contacts.select(contact => new contactmodel(contact)).tolist(); } }
controller
public jsonresult readcontacts([datasourcerequest]datasourcerequest request) { var contacts = _contactsdataprovider.read(); // database call, etc. datasourceresult result = contactmodel.flattentothis(contacts).todatasourceresult(request); homecoming json(result, jsonrequestbehavior.allowget); }
but don't think ever made philly. ;)
kendo-ui kendo-grid
No comments:
Post a Comment