我正在尝试在控制器上设置kendo网格的页面索引,以避免客户端分页。使用客户端分页时,除第一页上的记录外,不显示任何记录。从控制器调用数据时,我只返回页面所需的10条记录。数据调用包括Skip()和Take()函数,只返回服务器所需而不是加载整个网格。
.cshtml
@(Html.Kendo().Grid<Reckon.Service.Payroll.Data.DTO.EmployeeDto>()
.Name("EmployeeGrid")
.Columns(cols =>
{
cols.Bound(emp => emp.Id).Title("ID").Hidden();
cols.Bound(emp => emp.EmployeeNumber).Title("Employee ID").Width(100);
cols.Bound(emp => emp.IsPayRunReady).Title("Status").Width(10).ClientTemplate("<span title='This employee is #= IsPayRunReady ? '': 'not '#payrun ready.' class='#= IsPayRunReady ? 'okICN-small' : 'alertICN-small'#'>#= IsPayRunReady ? '': 'Not' # #= IsPayRunReady ? 'P':'p'#ayrun ready</span>");
cols.Bound(emp => emp.FirstName).Title("First Name").Width(100);
cols.Bound(emp => emp.LastName).Title("Last Name").Width(100);
cols.Bound(emp => emp.DateOfBirth).Title("DOB").Format("{0:dd/MM/yyyy}").Width(100);
cols.Template(@<text></text>).ClientTemplate("<a href='" + Url.Action("EmployeeDetailEdit", "EmployeeDetail") + "/#=Id#'>Edit</a>").Width(50);
cols.Template(@<text></text>).ClientTemplate("<a href='" + Url.Action("EmployeeDetailRead", "EmployeeDetailRead") + "/#=Id#'>View</a>").Width(50);
cols.Template(@<text></text>).ClientTemplate("<a class='k-button xxx' tag='#=Id#'>Delete</a>").Width(50);
})
.Pageable(pageable => pageable.ButtonCount(5))
.Sortable(sortable => sortable.AllowUnsort(false))
.Filterable()
.Resizable(resize => resize.Columns(true))
.Reorderable(reorder => reorder.Columns(true))
.Navigatable()
.Events(evt => evt.DataBound("afterGridLoaded"))
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.PageSize(10)
.ServerOperation(false)
.Model(model =>
{
model.Id(emp => emp.Id);
})
.Read(read => read.Action("EmployeeListPerPage", "EmployeeDetail"))
)
)
的.cs
public ActionResult EmployeeListPerPage([DataSourceRequest] DataSourceRequest request)
{
Dispose();
EmployeeListRequest empList = new EmployeeListRequest();
empList.PageNum = request.Page;
empList.PageSize = request.PageSize;
//empList.OrderBy = null; //request.Sorts.Any() ? "EmployeeNumber" : request.Sorts[0].Member;
var dataSource = _payrollService.GetEmployeeListPerPage(empList);
var model = new EmployeeListModel(dataSource);
DataSourceResult result = model.Employees.ToDataSourceResult(request);
result.Total = dataSource.Total;
// Set the Page index here
return Json(result, JsonRequestBehavior.AllowGet);
}
使用客户端分页时,它将返回数据设置为第一页,然后执行客户端分页,不返回任何结果。
有可能吗? 任何帮助将不胜感激。
答案 0 :(得分:1)
由于您正在使用Entity Framework,因此请将控制器更改为此以让Kendo / EF处理分页(它将是服务器端):
public ActionResult EmployeeList([DataSourceRequest] DataSourceRequest request)
{
var employees = from emp in dbContext.Employees
select emp;
return Json(employees.ToDataSourceResult(request), JsonRequestBehavior.
}
这是一个粗略的例子,但应该是一个起点。