How can I mapping nested Json to Kendo UI grid?

╄→гoц情女王★ 提交于 2020-07-23 06:19:32

问题


I use a web api to send data to display in Kendo UI grid. my web api return a nested json. As follows:

{
"SearchRequest": {
        "Term": null,
        "SortDirection": "Desc",
        "Total": 0,
        "PageIndex": 1,
        "PageSize": 10,
        "CurrentSort": null
    },
    "OperationalRisks": [
        {
            "LocationCode": 224.0,
            "RegisterDate": "1/01/01"
        },
        {
            "LocationCode": 211.0,
            "RegisterDate": "1/01/01"
        }
 ]
}

After that, I will try to display the data in the following way :

columns: [
                    { field: "OperationalRisks.LocationCode", title: "#" },
                    { field: "OperationalRisks.RegisterDate", title: "#" }
                ]

And:

schema: {
                    model: {
                        fields: {
                            "OperationalRisks.LocationCode": { type: "number" }, 
                            "OperationalRisks.RegisterDate": { type: "number" }
                        }
                    }
                }

But the data isn't bind to grid


回答1:


My problem was easily solved and I would like to share this with you first of all you should define:

var json_data;

and after that:

$("#grid").kendoGrid{{
datasource:{
type:"json",
data:json_data.OperationalRisks,
.
.
.

columns: [
           { field: "LocationCode", title: "#" },
           { field: "RegisterDate", title: "#" }
         ],
.
.
.
schema: {
                    model: {
                        fields: {
                            "LocationCode": { type: "number" }, 
                            "RegisterDate": { type: "number" }
                        }
                    }
                }


来源:https://stackoverflow.com/questions/62971752/how-can-i-mapping-nested-json-to-kendo-ui-grid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!