具有 OData 格式的剑道网格数据源 = json [英] kendo Grid DataSource with OData format = json

查看:21
本文介绍了具有 OData 格式的剑道网格数据源 = json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有 asp.net web api odata 启用服务,支持各种 OData 格式,例如 application/json;odata=fullmetadata

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

此服务与 WCF 数据服务客户端JayData

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:

运行正常的 kendoUI 站点的演示有以下响应:

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

"__count": "91"

响应内容类型为:text/javascript;charset=utf-8

您可以在以下位置查看剑道 UI 演示示例:

You can see the sample of kendo UI demo at:

http://demos.kendoui.c​​om/web/grid/index.html

这是我们的回应:

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

响应内容类型为:application/json;odata=完整元数据;charset=utf-8

我可以拥有生成所需格式的 ODataMediaTypeFormatter 吗?或者是否有任何解决方案可以使 KendoDataSource 与我们当前的响应一起工作?任何其他解决方案表示赞赏.

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.

请注意,我们已使用 type: "odata"

谢谢

推荐答案

这是因为 KendoUI 仍然以 OData V2 格式进行通信,而您的服务器正在使用 OData V3.

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

要解决此问题,您可以在服务器端使用 V2 或通过将以下配置添加到数据源对象来改进 KendoUI 传输处理响应的方式:

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'];
                }
            },

因此剑道网格将理解 total 将位于响应的 totalCount 部分而不是 "__count">

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

这篇关于具有 OData 格式的剑道网格数据源 = json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆