joeharrison714 / MVCGrid.Net

http://mvcgrid.net
MIT License
75 stars 56 forks source link

Grid doesn't page results, shows all records and pager also #117

Open sudipta-chaudhari opened 7 years ago

sudipta-chaudhari commented 7 years ago

Hi,

The grid is being displayed which has pager enabled but displays all records without paging. Also the pager is displayed. Code for RegisterGrid() method is as below:-

public static void RegisterGrids()
        {
            GridDefaults defaultSet1 = new GridDefaults()
            {
                Paging = true,
                ItemsPerPage = 5,
                NoResultsMessage = "Sorry, no results were found"
            };

            MVCGridDefinitionTable.Add("grdFiles", new MVCGridBuilder<FilesModel>(defaultSet1)
            .WithAuthorizationType(AuthorizationType.AllowAnonymous)
            .AddColumns(cols =>
            {
                cols.Add("FileName")
                    .WithValueExpression(p => p.Name.ToString());
                cols.Add("LastModified").WithHeaderText("LastModified")
                    .WithValueExpression(p => p.LastModified.ToString());
                cols.Add("Size").WithHeaderText("Size")
                    .WithValueExpression(p => p.Size.ToString());
            })
            .WithRetrieveDataMethod((context) =>
            {
                var res = DisplayFiles();
                return new QueryResult<FilesModel>()
                {
                    Items = res,
                    TotalRecords = res.Count // if paging is enabled, return the total number of records of all pages
                };
            })
            );
        }

View Code is:

@model IEnumerable<FileViewerWeb.Models.FilesModel>

@using MVCGrid.Web;

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="well well-lg" style="padding-top:10px">
    <h2>Explore Uploaded Files</h2>
</div>

@Html.MVCGrid("grdFiles")

Controller Code:-

public ActionResult Index()
{
return View();
}