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

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

问题描述

我们的 asp.net网页API 的ODATA启用服务,支持多种格式的OData的如应用程序/ JSON; ODATA = fullmetadata

此服务与伟大的工作 WCF数据服务客户端 JayData

但我们的反应似乎不是与我们的剑道电网数据源兼容

我已经调查了响应,这里的区别是:

这是工作的罚款kendoUI现场演示有以下回应:

 __计:91

和响应内容类型是:文/ JavaScript的;字符集= UTF-8

您可以看到剑道UI演示的示例:

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

这是我们的回应:

<$p$p><$c$c>\"odata.metadata\":\"http://localhost:2452/odata/$metadata#VehicleGroups\",\"odata.count\":\"29\",\"value\":[

和响应内容类型是:应用程序/ JSON的; ODATA = fullmetadata;字符集= UTF-8

我可以有一个生成所需格式的ODataMediaTypeFormatter?
或者是有任何解决方案,使KendoDataSource与我们的电流响应?
任何其他的解决方案是AP preciated。

请注意,我们已经启用的OData为KendoDataSource与键入:ODATA

感谢


解决方案

这是因为KendoUI依然在V2的OData格式进行通信,服务器与OData的V3操作。

要解决这个问题,你可以使用V2在你的服务器端或改进KendoUI运输如何处理通过添加以下配置到数据源对象的响应:

 模式:{
                数据:功能(数据){
                    返回data.value;
                },
                总:功能(数据){
                    返回数据['odata.count'];
                }
            },

所以剑道电网将明白, 将在 TOTALCOUNT 的响应,而不是__计数的栏目

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

解决方案

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"

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

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