我正在将我的应用程序转换为使用带有 Kendo Grid UI 的服务器端分页。 在将 serverPaging 切换为 true 之前,我正确地显示了网格内容,并在客户端进行分页。 然而,一旦我打开服务器分页,我的数据就不再可见。 我已经检查了网络调用,并且我的数据正在按预期返回(总共 8 条记录中只有 2 条记录),但我没有在网格中看到它。
这是网格构建:
$v.KendoGrid.makeGrid(gridName, {
columns: [
{ field: 'IdentifierCode', title: 'User Name' },
{ field: 'CompanyName', title: 'Company' },
{ field: 'Email', title: 'Email' }
],
dataSource: {
pageSize: 2,
schema: {
data: 'Data', // records are returned in the data section of the response
model: {
id: 'Id',
fields: {
IdentifierCode: { type: 'string' },
CompanyName: { type: 'string' },
Email: { type: 'string' }
}
},
total: 'Total' // total number of records are in the total section of the response
},
serverPaging: true,
transport: {
read: {
url: window.urlConfigs.root + "Security/UserAccount/PagedListing"
dataType: "json",
type: "GET"
}
}
},
editable: false,
filterable: true,
height: 464,
pageable: true,
scrollable: true,
sortable: true
});
这是 MVC 控制器方法:
public ActionResult PagedListing(int pageSize, int skip)
{
var entities = ReadRepo.All();
var total = entities.Count();
var data = entities.Skip(skip).Take(pageSize).Select(MapEntityToViewModel).ToList();
return Json(new { Total = total, Data = data }, JsonRequestBehavior.AllowGet);
}
这是我通过网络调用返回的数据:
{"Total":8,"Data":[{"Id":"928f0bb2-608b-417b-bf6e-e5c58f85fec2","IdentifierCode":"admin","FirstName":"Administrator","MiddleName":"of","MiddleNameHuman":"of","LastName":"GasStream","DisplayName":"Administrator of GasStream","Email":"[email protected]","IsExternal":false,"UserTypeHuman":"Internal","CompanyId":"75bb05a4-1ec2-4042-aeba-a229008aca9f","CompanyName":"Entessa Pipeline & Terminal, MLP","CompanyIdentifierCode":"SHA","Password":"wFg/a/NEU6WM8z4YZBUduitIDROfeFz/+Za6leAHnBE=","PasswordChanged":false,"ForceNewPasswordFlag":false,"Settings":[],"RoleGroups":[]},{"Id":"47c29025-cfa8-4447-9ab7-a229008ad088","IdentifierCode":"contractcarl","FirstName":"Carl","MiddleName":null,"MiddleNameHuman":"","LastName":"Smithers","DisplayName":"Carl Smithers","Email":"[email protected]","IsExternal":false,"UserTypeHuman":"Internal","CompanyId":"75bb05a4-1ec2-4042-aeba-a229008aca9f","CompanyName":"Entessa Pipeline & Terminal, MLP","CompanyIdentifierCode":"SHA","Password":"IWdH+qDIOucNrre6V4AgI6Exm2Vq5qkIdXdsWfP6jn4=","PasswordChanged":false,"ForceNewPasswordFlag":false,"Settings":[],"RoleGroups":[]}]}
我怀疑我错过了一些小东西,但是在查看了这个并尝试了各种可能的解决方法之后,我看不到它,所以我寻求一些帮助。 我想一旦我得到了从服务器返回小集合的数据,事情就会变得更简单。
提前致谢,
德鲁
我最终找到了答案。 $v.KendoGrid 是一种包装 kendoGrid 调用本身的方法,其中某些内容正在被重置,以便当数据从服务器正确分页返回时不允许正确解析数据。
此后我重新处理了混乱的情况,以便我可以在 $v.KendoGrid 调用中为我的网格类型建立必要的参数。
感谢您的帮助,以及捕捉逗号的眼睛,布雷特。
德鲁