【发布时间】:2014-08-19 20:29:37
【问题描述】:
我正在尝试通过 Kendo UI Grid 使用服务器端分页,但我遇到了似乎没有在任何地方记录的错误。
我收到的错误是:
Unhandled exception at line 11, column 15140 in kendo.all.min.js
0x800a138f JavaScript runtime error: Unable to get property 'slice' of undefined or null reference.
根据我在网上找到的文档和其他示例,我使用以下方法绑定我的剑道网格:
var postData = { "searchTerm" : searchTerm, "targetDB" : targetDB, "searchObj" : searchObj }
var grid = $("#grid1").kendoGrid({
pageable: {
pageSize: 40
},
dataSource: {
error: function (e) {
if (e.errors !== false) {
$("#errorContainer").html(e.errors);
}
},
transport: {
read: {
url: servicePath,
dataType: "json",
data: postData,
type: "POST"
}
},
serverPaging: true,
schema: {
total: "total",
data: "data"
}
},
dataBound: function (e) {
var end = new Date().getTime();
var time = end - start;
console.log("Time taken: " + time);
$("#loading").hide();
$("#grid1").show();
$("#totalTimeBadge").html(time + " milliseconds");
$("#totalCountBadge").html(this.dataSource.total() + " items");
$("#propertyCountBadge").html($(".k-header").length + " properties");
logTimes(time, this.dataSource.total(), $(".k-header").length);
}
});
我使用帖子的原因是(您可能会猜到)我正在实现搜索功能,并使用 Kendo Grid 发布搜索条件和我想要搜索的目标数据库(有两种可能性) .
我已经通过 jslint 运行返回的 JSON 并验证它是有效的 JSON,其结构是:
[{
"total": 50053,
"data": [{objects}]
}]
如果我需要发布更大的 JSON 实际摘录,我可以在这里发布。
我在这里跟踪这个问题的答案:Error while implementing basic paging in Kendo UI Grid in ASP.NET
但是这个问题不使用剑道网格来发布和检索项目(不知道这是否会有所不同),而且我还验证了这个问题的唯一答案不适用于我的实例。
如果我取出 total 数据字段并且只返回我的响应的原始数据,网格绑定就好了,但我需要合并服务器端分页。
有什么想法吗?谢谢!
更新
根据下面的建议,我尝试将控制器从返回直接字符串更改为使用 DataSourceResult:
public ActionResult DataSourceResult()
{
string dataStr = "[{\"NAME\": \"0720-FI-1081\", \"DESCRIPTION\": \"HP FLARE HEADER DISTRIBUTION\"},{\"NAME\": \"0720-FIC-1002\",\"DESCRIPTION\": null}]";
DataSourceResult result = new DataSourceResult();
result.Data = dataStr;
result.Total = 50;
string json = JsonConvert.SerializeObject(result);
return Content(json, "application/json");
}
同样的错误。
【问题讨论】:
标签: javascript asp.net-mvc json kendo-grid