【发布时间】:2015-07-22 22:36:11
【问题描述】:
我有一个使用许多剑道网格的页面。每个网格都定义了一个数据源,该数据源对 Wep API 2.0 资源进行 ajax 调用。
Fiddler 显示正在进行 ajax 调用并且正在正确返回数据。但是,网格似乎对它没有任何作用。我在网格上有一个 dataBound 属性的函数,它从未被调用过。
有什么想法吗?
更新
这是代码和返回的数据。
数据源
var getUnassignedCases = new kendo.data.DataSource({
type: "odata",
transport: {
read: {
url: hostUrl + "/api/cases/getUnassignedCases/" + sakUser,
dataType: "jsonp",
cache: false,
data: { id: sakCase }
},
scrollable: {
virtual: true
},
pageSize: 10,
resizable: true,
sortable: {
mode: "single",
allowUnsort: true
},
pageable: {
input: true,
numeric: false,
buttonCount: 10
}
},
schema: {
model: {
id: "SakCase",
fields: {
SakCase: { type: "number" },
CaseId: { type: "string" },
SakIntake: { type: "string" },
CaseTypeDescription: { type: "string" },
DateCreated: { type: "date" },
CaseStatusCode: { type: "string" }
}
}
},
pageSize: 10
});
网格
DisplayNoResultsFound 函数从未被调用(就目前而言),所以我没有包含源代码。
$("#UnassignedCasesGrid").kendoGrid({
columns: [
{ field: "CaseId", title: "Case ID", width: 150, template: "<a href='/Arms/Case_Information.aspx?SakCase=${SakCase}'>${CaseId}</a>" },
{ field: "SakIntake", title: "Intake ID", template: "#if (SakIntake === null) {# #} else {#<a href='/Arms/Intake.aspx?SakIntake=${SakIntake}'>${SakIntake}</a>#} #" },
{ field: "CaseTypeDescription", title: "Case Type", width: 100 },
{ field: "DateCreated", title: "Date Created", format: '{0:MM/dd/yyyy}', width: 100, editor: dateTimeEditor },
{ field: "CaseStatusCode", title: "Case Status" }
],
dataSource: getUnassignedCases,
dataBound: function () {
DisplayNoResultsFound($('#UnassignedCasesGrid'), 'UnassignedCasesCount', 'Unassigned Cases');
},
type: "aspnetmvc-ajax",
groupable: false,
scrollable: {
virtual: true
},
pageSize: 10,
resizable: true,
sortable: {
mode: "single",
allowUnsort: true
},
pageable: {
buttonCount: 10
}
});
从 Web API 调用返回
前几个字段。标头中的长度反映了返回的 100 个测试行。
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Fri, 24 Jul 2015 17:46:56 GMT
Content-Length: 14993
[
{
"SakCase": 1,
"CaseId": "2015M00001",
"SakIntake": null,
"CaseTypeDescription": "Medical Review",
"DateCreated": "2014-08-04T17:19:59",
"CaseStatusCode": "O"
},
{
"SakCase": 2,
"CaseId": "2015M00002",
"SakIntake": null,
"CaseTypeDescription": "Medical Review",
"DateCreated": "2013-03-20T08:02:46",
"CaseStatusCode": "O"
}
]
调用后的DOM
以下内容取自 chrome 检查元素。
这是列的定义:
<thead role="rowgroup">
<tr role="row">
<th role="columnheader" data-field="CaseId" data-title="Case ID" class="k-header" data-role="sorter">
<a class="k-link" href="#">Case ID</a>
</th>
<th role="columnheader" data-field="SakIntake" data-title="Intake ID" class="k-header" data-role="sorter">
<a class="k-link" href="#">Intake ID</a>
</th>
<th role="columnheader" data-field="CaseTypeDescription" data-title="Case Type" class="k-header" data-role="sorter">
<a class="k-link" href="#">Case Type</a>
</th>
<th role="columnheader" data-field="DateCreated" data-title="Date Created" class="k-header" data-role="sorter">
<a class="k-link" href="#">Date Created</a>
</th>
<th role="columnheader" data-field="CaseStatusCode" data-title="Case Status" class="k-header" data-role="sorter">
<a class="k-link" href="#">Case Status</a>
</th>
</tr>
</thead>
这是表格的内容:
<table role="grid">
<colgroup>
<col style="width:150px">
<col>
<col style="width:100px">
<col style="width:100px">
<col>
</colgroup>
<tbody role="rowgroup"></tbody>
</table>
【问题讨论】:
-
您在浏览器的控制台中看到任何错误吗?如果数据被推送回浏览器,那么我怀疑将数据绑定到网格(通常是自定义模板)出现问题,您是否有示例可以帮助您解决此问题?
-
而且完全没有错误。此外,网格/模板在某些情况下也有效。主要是如果使用IE并且数据类型更改为json。但是,我们正在测试一个新服务器,即使它也无法正常工作(但它仍然可以在开发环境中工作)。
-
您是否尝试过取出列上的模板,以确保它们不会干扰网格数据的呈现?
标签: kendo-grid asp.net-web-api2