2016-12-26 75 views
0

我正在使用剑道网格服务器端分页。我在数据库端对数据进行排序和提取,这给我提供了只有pagesize数量的记录。我也从后端本身获得了全部记录的数量。我只想将这些数据绑定到kendo网格上,根据返回的计数显示页码。kendo ui grid完成服务器端分页和设置总数

即对于每一个下一个页面请求,我只返回pagesize(例如15)个记录总数的记录。以下是我的剑道网格代码。请帮助我绑定这些记录并根据总数显示页码。

@(Html.Kendo().Grid(Model.InvoiceList) 
.Name("InvoiceGrid") 
.Columns(columns => 
{ 
columns.Bound(p => p.CompanyName).Title("Company Name").Width(80); 
columns.Bound(p => p.Account).Title("Account").Width(60); 
columns.Bound(p => p.MerchantNumber).Title("Merchant No.").Width(60); 
columns.Bound(p => p.InvoiceAmount).Title("Invoice Amount").Width(60); 
columns.Bound(p => p.ReferralPercentage).Title("Referral %").Width(60); 
columns.Bound(p => p.ReferralCommission).Title("Referral Com.").Width(60); 
columns.Bound(p => p.DeveloperPercentage).Title("Developer %").Width(60); 
columns.Bound(p => p.DeveloperCommission).Title("Developer Com.").Width(60); 
}) 
.Pageable(
) 
.Sortable() 
.Filterable(filterable => filterable 
    .Extra(false) 
    ) 
.DataSource(dataSource => dataSource 
.Ajax() 
    .Batch(false) 
    .PageSize(15) 
     .ServerOperation(true) 
     .Read(read => read.Action("Index", "Invoice") 
    ).Total(Model.count) 
) 
) 

我用来获取记录的服务器端代码如下。

public async Task<ActionResult> IndexAsync(int pageNo=0,int numberOfRecord=15) 
    { 

     //InvoicePaging has invoice list of 15 records and count = 400 
     InvoicePaging ip = await InvoiceDAL<FileRecord>.getAllInvoices("SProcGetInvoiceList", pageNo, numberOfRecord); 
     return View("InvoiceList",ip); 
    } 

发票分页类 -

public class InvoicePaging 
{ 
    [JsonProperty(PropertyName = "InvoiceList")] 
    public List<Invoice> InvoiceList { get; set; } 

    [JsonProperty(PropertyName = "count")] 
    public int count { get; set; } 
} 

回答

0

寻找问题的解决方案后,我得到了下面的代码为我工作。

@(Html.Kendo().Grid<Commission.Vault.Models.Invoice>() 
.Name("InvoiceGrid") 
.Columns(columns => 
{ 
columns.Bound(p => p.CompanyName).Title("Company Name").Width(80); 
columns.Bound(p => p.Account).Title("Account").Width(60); 
columns.Bound(p => p.MerchantNumber).Title("Merchant No.").Width(60); 
columns.Bound(p => p.InvoiceAmount).Title("Invoice Amount").Width(60); 
columns.Bound(p => p.ReferralPercentage).Title("Referral %").Width(60); 
columns.Bound(p => p.ReferralCommission).Title("Referral Com.").Width(60); 
columns.Bound(p => p.DeveloperPercentage).Title("Developer %").Width(60); 
columns.Bound(p => p.DeveloperCommission).Title("Developer Com.").Width(60); 
}) 

.EnableCustomBinding(true) 
.BindTo(Model.InvoiceList) 
.Pageable(
) 
.Sortable() 
.Filterable(filterable => filterable 
    .Extra(false) 
    ) 
.DataSource(dataSource => dataSource.Server().Total(Model.count).PageSize(15) 
) 
) 

和代码背后它在Asp.net是

public async Task<ActionResult> IndexAsync([DataSourceRequest(Prefix = "InvoiceGrid")] DataSourceRequest request) 
    { 
     List<Invoice> il = new List<Invoice>(); 
     int pageNo = request.Page-1,numberOfRecord=15; 
     InvoicePaging ip = await InvoiceDAL<FileRecord>.getAllInvoices("SProcGetInvoiceList", pageNo, numberOfRecord); 
     return View("InvoiceList",ip); 
    } 

的唯一的事情是,我总是得到的pageSize为0。其他的一切完美的工作。