【问题标题】:MVCGrid.Net - Paging not limiting results or page numbers not showingMVCGrid.Net - 分页不限制结果或页码不显示
【发布时间】:2020-03-11 22:43:36
【问题描述】:

我正在使用 MVCGrid.Net,我正在尝试向网格添加分页,这是我的代码:

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);
}

我在这里关注了这个演示:http://mvcgrid.net/demo/paging

我的代码有点不同,因为我有多个控制器,每个控制器都有一个网格,所以我在控制器中定义了我的网格,但是是的……我的分页没有出现,所有的结果都出现了……什么是我做错了吗?

【问题讨论】:

    标签: c# asp.net mvcgrid.net


    【解决方案1】:

    解决了:

    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;
                };
    

    【讨论】:

      猜你喜欢
      • 2017-10-20
      • 1970-01-01
      • 2017-08-31
      • 1970-01-01
      • 2018-04-12
      • 2014-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多