【问题标题】:page count in jqgrid with server side paging带有服务器端分页的 jqgrid 中的页数
【发布时间】:2014-07-27 04:40:28
【问题描述】:

我正在为 JQGrid(使用 MVC4)实现服务器端分页。我能够做到这一点。我没有使用 JQGrid 的寻呼机选项。相反,我正在使用自定义寻呼机实现。为此,我需要获取服务器返回的总页数。

我尝试了以下方法:

grid.getGridParam('lastpage')  -- always returns 1, which makes sense as I am returning only one page contents to the grid
grid.getGridParam('total')  -- I tried this because I was setting this value in the controller, but it is returning null
grid.getGridParam('records') -- always returns 10, my page size.

【问题讨论】:

    标签: jquery asp.net-mvc-4 jqgrid paging


    【解决方案1】:

    我想你以错误的方式使用loadonce: true 选项。该选项的目标是客户端分页、排序和过滤/搜索。如果使用loadonce: true 选项,服务器必须返回所有行。在使用loadonce: true 选项的情况下,值totalrecordspage 将被忽略,并且将根据从服务器返回的项目总数设置相应的值。因为您只返回了 10 个项目(第一页的项目),所以参数的值与您在问题中描述的完全一样。顺便说一句,如果您没有那么大的数据集(例如 1-1 万行),我建议您使用 loadonce: true 选项。服务器应返回按请求参数(sidxsord)排序的 all 项。可以只从服务器返回所有已排序项目的数组,而无需任何其他信息。

    顺便说一下jqGrid的页面相关参数的含义如下:

    • page - 当前页面的从 1 开始的编号
    • lastpage - 最后一页的页码
    • rowNum - 页面大小 - 一个页面中的最大记录数(最后一页可以包含较少的记录)
    • 记录 - 网格中的总记录(在所有页面上)
    • reccount - 页面中显示的记录总数(小于或等于页面 大小行数)

    【讨论】:

      【解决方案2】:

      如果你使用的是dataType : "json",那么你需要在jqGrid的jsonReader属性中设置这些值,

       $("#gridid").jqGrid({
          ...
             jsonReader : { 
                root: "rows", 
                page: "page", 
                total: "total", 
                records: "records", 
                repeatitems: true, 
                cell: "cell", 
                id: "id",
                userdata: "userdata",
                subgrid: { 
                   root:"rows", 
                   repeatitems: true, 
                   cell:"cell" 
                } 
             },
          ...
          });
      

      最后是发送到服务器以获取数据的值。因此,如果您必须覆盖这些值,则需要更改这些值。

      所以,请确保您在服务器端使用相同的值来获取这些值。

      【讨论】:

        猜你喜欢
        • 2015-09-07
        • 1970-01-01
        • 2014-05-17
        • 1970-01-01
        • 2010-10-31
        • 2011-06-16
        • 2011-06-20
        • 1970-01-01
        • 2013-11-23
        相关资源
        最近更新 更多