Reputation: 11861
I am using MVCGrid.Net and I am trying to add pagination to the grid, Here is my code:
GridDefinition<DepositLog> def = new GridDefinition<DepositLog>();
GridColumn<DepositLog> ID = new GridColumn<DepositLog>();
ID.ColumnName = "ID";
ID.HeaderText = "ID";
ID.HtmlEncode = false;
ID.ValueTemplate = "<input type='text' name='ID' value='{Value}' class='form-control' />";
ID.ValueExpression = (i, c) => i.id.ToString();
def.AddColumn(ID);
GridColumn<DepositLog> PayTo = new GridColumn<DepositLog>();
PayTo.ColumnName = "PayTo";
PayTo.HeaderText = "PayTo";
PayTo.HtmlEncode = false;
PayTo.ValueTemplate = "<input type='text' name='PayTo' value='{Value}' class='form-control' />";
PayTo.ValueExpression = (i, c) => i.PayTo.ToString();
def.AddColumn(PayTo);
GridColumn<DepositLog> Category = new GridColumn<DepositLog>();
Category.ColumnName = "Category";
Category.HeaderText = "Category";
Category.HtmlEncode = false;
Category.ValueTemplate = "<input type='text' name='Category' value='{Value}' class='form-control' />";
Category.ValueExpression = (i, c) => i.Category.ToString();
def.AddColumn(Category);
def.Paging = true;
def.ItemsPerPage = 10;
def.RetrieveData = (options) =>
{
return new QueryResult<DepositLog>()
{
Items = _modelItems,
TotalRecords = 0
};
};
try
{
MVCGridDefinitionTable.GetDefinition<DepositLog>("DepositLogGrid");
}
catch (Exception e)
{
MVCGridDefinitionTable.Add("DepositLogGrid", def);
}
I followed this demo here: http://mvcgrid.net/demo/paging
My code is a little bit different because I have multiple Controllers each with a grid, so I define my grid in the Controller, but yea...my paging is not appearing and all the results come up...what am i doing wrong?
Upvotes: 0
Views: 78
Reputation: 11861
Solved it:
def.Paging = true;
def.ItemsPerPage = 25;
def.MaxItemsPerPage = 25;
def.RetrieveData = (context) =>
{
var options = context.QueryOptions;
var result = new QueryResult<DepositLog>();
var query = _modelItems.AsQueryable();
result.TotalRecords = query.Count();
if (options.GetLimitOffset().HasValue)
{
query = query.Skip(options.GetLimitOffset().Value).Take(options.GetLimitRowcount().Value);
}
result.Items = query.ToList();
return result;
};
Upvotes: 0