我想在Kendo网格上做的是将选定列的id传递给控制器,返回的数据将是同一页面上第二个kendo网格的数据源,不会有任何页面加载或刷新。
Everthing在服务器端运行良好。所需数据数据将以json格式返回查看,但第二个网格无法显示数据。
JS:
e.preventDefault();
var tr = $(e.target).closest("tr"); // get the current table row (tr)
var dataItem = this.dataItem($(e.target).closest("tr"));
//Data that coming from kendo grid's selected column
var code = dataItem.CODE;
// alert(code);
var crudServiceBaseUrl = "/Administrator/DefinitionDetailRead/",
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: crudServiceBaseUrl,
data: { DefinitionCode: code },
dataType: "json"
},
update: {
url: crudServiceBaseUrl + "/Products/Update",
dataType: "json"
},
destroy: {
url: crudServiceBaseUrl + "/Products/Destroy",
dataType: "json"
},
create: {
url: crudServiceBaseUrl + "/Products/Create",
dataType: "json"
},
},
//batch: true,
pageSize: 9,
schema: {
model: {
ID: "ID",
fields: {
ID: { editable: false, nullable: true },
DESCRIPTION: { validation: { required: true } }
}
}
}
});
$("#detailsGrid").kendoGrid({
dataSource: dataSource,
attributes: {
style: "padding-left: 0px; font-size: 14px"
},
pageable: {
refresh: false,
pageSizes: false,
buttonCount: 5
},
toolbar: ["create"],
columns: [
{
field: "DESCRIPTION",
title: "DESCRIPTION",
//filterable: {
// ui: titleFilter
//},
width: "200px"
},
{ command: ["edit", "destroy"], title: "Operation", width: "100px" }],
editable: "popup"
});
控制器:Everthing在这里工作。
public ActionResult DefinitionDetailRead([DataSourceRequest] DataSourceRequest request, string DefinitionCode)
{
DataSourceResult result = null;
var lang = CultureHelper.GetCulture();
using (var client = SoapProxyFactory.CreateDSrvGDSoapClient())
{
var pSize = request.PageSize;
var pIndex = request.Page;
var totalsize = client.GetDefinitionDetailsTotalCount(DefinitionCode, lang);
var dataresult = client.GetDefinitionDetails(DefinitionCode, lang, false);
var items = dataresult.RootResults;
result = items.ToDataSourceResult(request, totalsize, null);
}
return Json(result, JsonRequestBehavior.AllowGet);
#endregion
}
来自控制器的Json数据:
{“Data”:[{“ExtensionData”:{},“CODE”:“ABNORMAL”,“CODETYPE”:null,“COUNT”:0,“DESCRIPTION”:“异常(在Resp下检查)”, “ENTRYDATE”:空, “ID”: “1b0a0cd8-8fed-4b34-9054-1e73942a16d2”, “ISACTIVE”:假 “ISDEFAULT”:假 “ISSELECTED”:假 “LANG”:NULL, “注1”:空, “NOTE2”:空, “ORDERINDEX”:空, “PARENTDESCRIPTION”:空, “PARENTID”: “00000000-0000-0000-0000-000000000000”, “REFERENCEID”:“3df1f5d7-bc04-4554-bf01-1a9d5b95eebb ”, “VALUE”:空}
答案 0 :(得分:2)
问题在于,您并未说明返回数据中的哪个实际上是包含数据的数组。
您的model
定义应为:
schema: {
data: "Data",
model: {
ID: "ID",
fields: {
ID: {
editable: false,
nullable: true
},
DESCRIPTION: {
validation: { required: true }
}
}
}
}
我已添加data: "Data"
通知KendoUI Grid需要检查Data
。
您在此处修改了示例:http://jsfiddle.net/OnaBai/ZEndW/
答案 1 :(得分:0)
将dataSource的类型指定为“aspnet-mvc”。在此之前,请确保已加载kendo.aspnetmvc.min.js文件。
此外,您还必须指定架构配置。
看起来应该是这样的:
"dataSource": {
"transport": {
"prefix": "",
"read": {
"url": ""
}
},
"pageSize": 20,
"page": 1,
"total": 0,
"type": "aspnetmvc-ajax",
"schema": {
"data": "Data",
"total": "Total",
"errors": "Errors",
"model": {
"fields": {
"id": {
"type": "number"
},
"quantity": {
"type": "number"
},
"name": {
"type": "string"
}
}
}
}
}