如何显示 jqGrid 中的所有行?

2022-01-19 00:00:00 jquery javascript jqgrid rowcount

jqGrid 公开了一个属性 rowNum,您可以在其中设置要为每个页面显示的行数.如何将网格设置为只显示所有行?

jqGrid exposes a property rowNum where you can set the number of rows to display for each page. How do you set the grid to just display ALL rows?

现在我只是将 rowNum 设置为非常高的值,例如 <%= int.MaxValue %> 但我想知道是否有更好的方法.

Right now I'm just setting the rowNum to something really high like <%= int.MaxValue %> but I'm wondering if there is a better way.

推荐答案

在最新版本的 jqGrid 中,您可以将 rowNum 设置为 -1 以指示网格始终显示所有行:

In the latest version of jqGrid, you can set rowNum to -1 to instruct the grid to always display all rows:

rowNum: -1

查看最新的 jqGrid 文档这里.

See the latest jqGrid documentation here.

具体来说:

设置我们要在网格中查看多少条记录.该参数被传递到 url 以供检索数据的服务器例程使用.请注意,如果您将此参数设置为 10(即检索 10 条记录)并且您的服务器返回 15,则只会加载 10 条记录.将此参数设置为 -1(无限制)以禁用此检查.

Sets how many records we want to view in the grid. This parameter is passed to the url for use by the server routine retrieving the data. Note that if you set this parameter to 10 (i.e. retrieve 10 records) and your server return 15 then only 10 records will be loaded. Set this parameter to -1 (unlimited) to disable this checking.


更新

不幸的是,这种行为在 jqGrid 3.6.3 中被破坏了.根据 这篇来自 Tony 的帖子:

Unfortunately this behavior was broken in jqGrid 3.6.3. According to this post from Tony:

是的,这是真的.原因是新推出的卷轴:1.以后我们会纠正这种行为.

Yes, this is true. The reason is the new introduced scroll:1. In the future we will correct this behavior.

所以 jqGrid 开发人员已经意识到了这个问题,并且显然计划在未来的版本中修复它.不幸的是,这篇文章是一年多前的……

So the jqGrid developers are aware of this problem and apparently are planning to fix it in a future release. Unfortunately this post was from over a year ago...

此时,我只能建议您将 rowNum 设置为一个非常大的数字,以模拟 -1 的行为.

At this time, all I can recommend is that you set rowNum to a very large number to simulate the behavior of -1.

您也可以尝试下面使用 rowNum: '' 的 whatispunk 解决方案.但是,我在包含本地数据的网格上进行了尝试(loadonce: true).当尝试对行进行排序时,所有网格的本地数据都会消失.所以这个解决方案似乎不适用于具有本地数据的网格,除非这个缺陷已经在 jqGrid 的更高版本中得到修复(我在 jqGrid 3.8.2 上测试过).如果您有任何反馈,请在下方发表评论!

You can also try whatispunk's solution below of using rowNum: ''. However, I tried this on a grid containing local data (loadonce: true). When attemping to sort the rows all of the grid's local data would disappear. So this solution does not seem to work for grids with local data, unless this defect has been fixed in a later version of jqGrid (I tested it on jqGrid 3.8.2). If you have feedback, please post a comment below!


更新 - 2014 年 4 月 16 日

根据 jqGrid 团队的说法,此问题现已修复:

我增加了对在寻呼机选择框上设置不同显示值的支持,包括全部 -1.

I have added support to set different display values on pager select box including -1 for all.

不过,我还没有机会进行测试以确认修复.估计这个变化会在 jqGrid 4.6.0 之后的下一个版本中.

I have not had a chance to test to confirm the fix, though. Presumably this change will be in the next release after jqGrid 4.6.0.

相关文章