kendo Grid DataSource with OData format = json

喜夏-厌秋 提交于 2019-12-21 21:38:44

问题


We've asp.net web api odata enabled service which supports variety of OData formats such as application/json;odata=fullmetadata

This services is working great with WCF Data Service Client and JayData

But our response seems not to be compatible with our kendo grid dataSource

I've investigated the response and here is the difference:

The demo of kendoUI site which is working fine has following response:

"__count": "91"

And the response content type is: text/javascript;charset=utf-8

You can see the sample of kendo UI demo at:

http://demos.kendoui.com/web/grid/index.html

And here is our response:

"odata.metadata":"http://localhost:2452/odata/$metadata#VehicleGroups","odata.count":"29","value":[

And the response content type is: application/json; odata=fullmetadata; charset=utf-8

Can I have a ODataMediaTypeFormatter that generates needed format? Or is there any solution to make KendoDataSource works with our current response? Any other solutions are appreciated.

Note that we've enabled OData for KendoDataSource with type: "odata"

Thanks


回答1:


This is because KendoUI still communicates in the OData V2 format and your server is operating with OData V3.

To solve this problem you can use V2 on your server side or refine how the KendoUI transport processes the response by adding the following configuration to the data source object:

            schema: {
                data: function (data) {
                    return data.value;
                },
                total: function (data) {
                    return data['odata.count'];
                }
            },

So kendo grid will understand that total will be at totalCount section of the response instead of "__count"



来源:https://stackoverflow.com/questions/20629748/kendo-grid-datasource-with-odata-format-json

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