سؤال

I am having problems with paging a WebGrid. Essentially, I pass the full data, it pages OK. If I limit the data to one page at a time, the paging controls disappear, despite the fact that I have passed in the rowCount.

Why?

See below for setup:

I have a grid defined as follows:

@{
    ViewBag.Title = "Cuentas";
    var grid = new WebGrid(defaultSort: "AccountName", rowsPerPage: 30, canPage: true, 
        ajaxUpdateCallback: "updateGrid");
    grid.Bind(source: Model.Accounts, rowCount: Model.TotalRows);
}

With its columns defined as follows:

<div id="grid">
    @grid.GetHtml(tableStyle:"grid",headerStyle:"head", alternatingRowStyle:"alt", htmlAttributes: new { id = "AccountsGrid"},
        columns:  grid.Columns(grid.Column(header: "", format: (item) => Html.ActionLink("Editar", "Edit", new { id = item.AccountId })),
                                grid.Column(header: "", format: (item) => Html.ActionLink("Eliminar", "Delete", new { id = item.AccountId })),
                                grid.Column("AccountName",header:"Nombre"), 
                                grid.Column("IsClient", header:"Cliente?"), 
                                grid.Column("IsProvider", header:"Proveedor?"), 
                                grid.Column("IsBank", header:"Banco o Caja?"),
                                        grid.Column("Person", format: item => new HtmlString(item.Person == null ? "" : item.Person.Name), header: "Contacto"),
                                        grid.Column("AccountsCostCentress", 
                                            format: item => new HtmlString(item.AccountsCostCentress == null ?
                                            "" : item.AccountsCostCentress.Count.ToString()), header: "Actividades")))
</div>

The ViewModel I am using in my view is defined as follows:

public class AccountsListViewModel
{
    public int PageSize { get; set; }
    public int PageNumber { get; set; }
    public IEnumerable<Account> Accounts { get; set; }
    public int TotalRows {get;set;}
}

This shows that I can pass the rowCount and the IEnumerable Accounts.

Lets say I have 305 rows of accounts. If I set PageSize to 30, that means I will have 11 pages of data (the last one will only have 5 records on it). If Accounts holds all 305 records, the grid works with paging and all.

If Accounts only holds the 30 records corresponding to page 3, for example, the paging control don't show, EVEN IF TotalRows == 305.

Can't figure it out. Can you? Or do you know of a blog post, thread or article I might look at??

هل كانت مفيدة؟

المحلول

Sorry! Answered my own question:

autoSortPage: false parameter missing from grid.Bind(...) method.

See the following SO thread:

WebGrid paging

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top