【发布时间】:2013-12-22 21:38:55
【问题描述】:
我正在尝试在控制器上为剑道网格设置页面索引,以避免客户端分页。使用客户端分页时,除了第一页之外不显示任何记录。从控制器调用数据时,我只返回页面所需的 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);
}
使用客户端分页时,将返回数据设置为第一页,然后执行客户端分页,不返回结果。
有可能吗? 任何帮助将不胜感激。
【问题讨论】:
-
你为什么不想使用剑道的分页?
-
剑道分页是客户端,当数据从服务器端返回时,它只会返回当前页面所需的 10 条记录。这些记录作为前 10 条记录绑定到网格,当您单击第一页以外的任何其他页面时,它不会显示任何其他记录。这就是我不想使用剑道分页的原因,因为我没有将所有数据返回到网格,而只返回当前所选页面所需的数据。
-
我不明白你为什么要这样做:
empList.PageNum = request.Page;你在那里做了很多额外的工作,基本上是在与剑道自动为你做的事情作斗争。如果您访问一个页面(通过查询字符串),它将为您返回正确的页面。 -
这个,empList.PageNum = request.Page;,因为函数 GetEmployeeListPerPage 接受了一个 EmployeeListRequest仅参数。可以举个例子吗?
-
您的
GetEmployeeListPerPage()方法是否返回IQueryable<T>,您使用的是实体框架还是nHibernate?看起来你仍然在尝试与剑道战斗。请参阅此处的第 7 步:docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/…
标签: asp.net-mvc asp.net-mvc-4 kendo-ui kendo-grid kendo-asp.net-mvc