Nonfactors mvcgrid paging problems

1.1k Views Asked by At

Ive just started using NonFactors.Grid.Mvc6 -Version 6.2.4. Ive got its basic functionality working and Im able to retrieve data from my serverside code (.net core 5). I want to implement paging but Im only able to get it to page through the dataset ive received on the clientside. For example, Ive returned 5 rows from the database, the grid only allows me to page through those 5 items. I cant find any documentation (or examples) of using ajax calls to retrieve the data in pages (specifying the current page and number of rows). This is of no use in the real world so the grid must be capable of this somehow (hopefully), but there is nothing documented. Has anyone managed to do this ? Id really appreciate some examples, the documentation is pretty poor

1

There are 1 best solutions below

0
On

I have the same problem, if I want to use the paging from the backend

Code example

.Pageable(pager =>
{
    pager.ShowPageSizes = true;
    pager.PageSizes = Model.Paging.PageSizes;
    pager.PagesToDisplay = Model.Paging.PagesToDisplay;

    pager.CurrentPage = Model.Paging.CurrentPage;
    pager.RowsPerPage = Model.Paging.RowsPerPage;

    pager.TotalRows = Model.Paging.TotalRows;
})

You can set the TotalRows value, but it will be recalculated for the _Pager.cshtml view based on the Rows.

public virtual IQueryable<T> Process(IQueryable<T> items)
    {
        TotalRows = items.Count();

My workaround, add/modify the following line to the _Grid.cshtml file:

    @if (Model.Pager != null)
{
    Model.Pager.TotalRows = Model.Pager.PagesToDisplay * Model.Pager.RowsPerPage;

    @await Html.PartialAsync(Model.Pager.PartialViewName, Model.Pager)
}