2016-12-26 219 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。其他的一切完美的工作。