如何显示jqGrid中的所有行?

发布于 2024-07-29 19:19:52 字数 180 浏览 5 评论 0原文

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

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

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?

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(15

泛泛之交 2024-08-05 19:19:52

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

rowNum: -1

请参阅最新的jqGrid文档此处

具体来说:

<罢工>

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



更新

不幸的是,这种行为在 jqGrid 3.6.3 中被破坏了。 根据托尼的这篇文章

是的,这是真的。 原因是新引入的卷轴:1。 将来我们将纠正这种行为。

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

此时,我所能建议的就是将 rowNum 设置为一个非常大的数字来模拟 -1


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


Update - April 16, 2014

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

我添加了在寻呼机选择框中设置不同显示值的支持,包括所有 -1。

不过,我还没有机会进行测试来确认修复。 据推测,此更改将在 jqGrid 4.6.0 之后的下一个版本中出现。


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

rowNum: -1

See the latest jqGrid documentation here.

Specifically:

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.


Update

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

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

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...

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


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!


Update - April 16, 2014

According to the jqGrid team this is now fixed:

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

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.

七度光 2024-08-05 19:19:52

jqgrid(无论如何3.5)似乎没有一个优雅的内置方法来做到这一点。 到目前为止,我发现的最好的方法是将如下内容添加到您的网格选项中:

rowList:[10,20,30,100000000],
loadComplete: function() {
    $("option[value=100000000]").text('All');
},

其中 100000000 是比您将返回的最大行数任意更高的数字,并且 option[value=] 行是您的用户界面看起来更好一点。 Jenky,但为我工作。

jqgrid (3.5 anyway) doesn't seem to have an elegant built in way to do this. The best I have found so far is to add something like the following to your grid options:

rowList:[10,20,30,100000000],
loadComplete: function() {
    $("option[value=100000000]").text('All');
},

Where the 100000000 is some arbitrarily higher number than the maximum # of rows you will ever return, and the option[value=] line is so your user interface looks a little nicer. Jenky, but works for me.

雪落纷纷 2024-08-05 19:19:52

这有效:

// Step1 - defines the rows
jqGridOptions.rowList =[10, 50, 100, 500, 'All'];
...
...
// Step2 - Change the 'All' to a meaningful value 
loadComplete: function (data) {
   $(".ui-pg-selbox option[value='All']").val(1000);
}

This works:

// Step1 - defines the rows
jqGridOptions.rowList =[10, 50, 100, 500, 'All'];
...
...
// Step2 - Change the 'All' to a meaningful value 
loadComplete: function (data) {
   $(".ui-pg-selbox option[value='All']").val(1000);
}
李白 2024-08-05 19:19:52

如果您根本不想使用分页,则更改服务器端代码以仅返回所有行。 根本不要使用 rows 参数。

如果您想要拥有行列表,但也有一个显示全部的选项,那么在网格属性中执行类似的操作

jQuery("#statement_mods").jqGrid({
  rowList:['ALL',30,50,100,200]
});

,然后在服务器端代码中确保忽略 rows 参数,如果 GET['rows']='ALL'

if you dont wish to use paging at all then change you server side code to simply return all the rows. dont use the rows parameter at all.

if you want to have the rowlist but also have an option to show all then do something like this in the grid properties

jQuery("#statement_mods").jqGrid({
  rowList:['ALL',30,50,100,200]
});

and then in the serverside code make sure that you ignore the rows parameter if GET['rows']='ALL'

俏︾媚 2024-08-05 19:19:52

设置 rowNum:-1 为我解决了这个问题

setting rowNum:-1 did the trick for me

忘东忘西忘不掉你 2024-08-05 19:19:52

如果您在导航栏上设置了分页,您还可以访问网格右下角写入的总行数,然后附加到生成的 RowList 选项。

做类似的事情:

    // Get the total number of rows and delete space between numbers (Split the content of the div depending of the language (for me french)

var val=jQuery("#pager_right div").text().split('sur')[jQuery("#pager_right div").text().split('sur').length-1].split(' ').join('');

    // And do the appending if the option isn't already added

if(!$(".ui-pg-selbox option[value='"+val+"']").length > 0)
    jQuery(".ui-pg-selbox").append($('<option></option>').val(val).html(val));

If you have set the pagination on the navbar, you can also access to the total number of rows written on the right-bottom of the grid and then append to the generated RowList option.

Do something like :

    // Get the total number of rows and delete space between numbers (Split the content of the div depending of the language (for me french)

var val=jQuery("#pager_right div").text().split('sur')[jQuery("#pager_right div").text().split('sur').length-1].split(' ').join('');

    // And do the appending if the option isn't already added

if(!$(".ui-pg-selbox option[value='"+val+"']").length > 0)
    jQuery(".ui-pg-selbox").append($('<option></option>').val(val).html(val));
没有心的人 2024-08-05 19:19:52

设置 rowNum: '' 您将获得所有行。

Setting rowNum: '' you get all rows.

凉宸 2024-08-05 19:19:52
Jqgrid.PagerSettings.PageSize = Max Row you want to display;
Jqgrid.ToolBarSettings.ToolBarPosition = ToolBarPosition.Hidden;
Jqgrid.PagerSettings.PageSize = Max Row you want to display;
Jqgrid.ToolBarSettings.ToolBarPosition = ToolBarPosition.Hidden;
风筝在阴天搁浅。 2024-08-05 19:19:52

我已经得到了这个工作:

$('#bla').jqGrid({
        ...
        'rowNum'      : 0,
        'loadOnce'    : true,
        'loadComplete': function(data) {
            $(this).jqGrid('setGridParam', 'rowNum', data.total);
        },
        ...
});

无论是否将 loadOnce 选项设置为 true,这都有效。 请注意,您必须首先将 rowNum 选项设置为 0,如果您省略此选项,它仍会默认显示 20 条记录。
另外,我假设您以记录的 JSON 读取器格式从服务器返回总行数。

I've got this working:

$('#bla').jqGrid({
        ...
        'rowNum'      : 0,
        'loadOnce'    : true,
        'loadComplete': function(data) {
            $(this).jqGrid('setGridParam', 'rowNum', data.total);
        },
        ...
});

This works with and without the loadOnce option set to true. Note that you have to set the rowNum option to 0 first, if you leave out this option it'll still default to the 20 records to show.
Also, I'm assuming you're returning the total rows from the server in the documented JSON reader format.

新雨望断虹 2024-08-05 19:19:52

通过简单的更改解决了它:
rowNum: inputDataArray.length

其中 inputDataArray 是我提供给网格的数组。

resolved it with simple change:
rowNum: inputDataArray.length

where inputDataArray is the array that I am providing to the Grid.

邮友 2024-08-05 19:19:52

默认情况下,JQ 网格最多显示 20 行,如果您不使用分页:

// To over come with this problem ,you can just write the bold    mark
   (rowNum:10000,):
   $("#MasterDataDefinationGrid").jqGrid({
            url: 'FetchData.aspx/GetDataFromDB',
            datatype: 'json',
            mtype: 'POST',
            height: 300,
            autowidth: true,
            serializeGridData: function (postData) {
                return JSON.stringify(postData);
            },
            ajaxGridOptions: { contentType: "application/json" },
            loadonce: true,
            colNames: [Your column names],
            colModel: [Your model],
            formatter: 'actions',
            pager: '#MasterDataDefinationPager', pgbuttons: false,pgtext:false,
            multiselect: false,
            ignoreCase: true,
            **rowNum: 10000,**
            loadtext: 'Loading ...',
            gridview: true,
            hidegrid: false,
            jsonReader: {
                page: function (obj) { return 1; },
                total: function (obj) { return 1; },
                records: function (obj) { return obj.d.length; },
                root: function (obj) { return obj.d; },
                repeatitems: false,
                id: "0"
            },
            caption: 'Data'
        });

By default the JQ grid show 20 rows Max ,if you are using not using pagination:

// To over come with this problem ,you can just write the bold    mark
   (rowNum:10000,):
   $("#MasterDataDefinationGrid").jqGrid({
            url: 'FetchData.aspx/GetDataFromDB',
            datatype: 'json',
            mtype: 'POST',
            height: 300,
            autowidth: true,
            serializeGridData: function (postData) {
                return JSON.stringify(postData);
            },
            ajaxGridOptions: { contentType: "application/json" },
            loadonce: true,
            colNames: [Your column names],
            colModel: [Your model],
            formatter: 'actions',
            pager: '#MasterDataDefinationPager', pgbuttons: false,pgtext:false,
            multiselect: false,
            ignoreCase: true,
            **rowNum: 10000,**
            loadtext: 'Loading ...',
            gridview: true,
            hidegrid: false,
            jsonReader: {
                page: function (obj) { return 1; },
                total: function (obj) { return 1; },
                records: function (obj) { return obj.d.length; },
                root: function (obj) { return obj.d; },
                repeatitems: false,
                id: "0"
            },
            caption: 'Data'
        });
呆橘 2024-08-05 19:19:52

您还可以进入 jquery.jqGrid.js 并将“rowNum:20”更改为“rowNum:Some-Really-Large-Number”。 定义 jqGrid 时,不要指定 rowNum。 然后将整个数据集返回到 jqGrid。

You can also go into jquery.jqGrid.js and change "rowNum:20" to "rowNum:Some-Really-Large-Number". When you define your jqGrid, don't specify rowNum. Then return your entire dataset back to jqGrid.

风为裳 2024-08-05 19:19:52

即使它仍然出现在文档中,从 jqGrid 4.5.4 开始,您无法将 rowNum 设置为 -1,它仍然可以再次工作(也许在早期版本中也是如此)。

Even if it still appears in the doc that you cannot set rowNum to -1 as of jqGrid 4.5.4 it works again (maybe in earlier version too).

叫嚣ゝ 2024-08-05 19:19:52
loadComplete: function (data) {
                //set our "ALL" select option to the actual number of found records
                $(".ui-pg-selbox option[value='ALL']").val(data.records);
}

这会将“ALL”选项更改为数据集中的实际记录数。

loadComplete: function (data) {
                //set our "ALL" select option to the actual number of found records
                $(".ui-pg-selbox option[value='ALL']").val(data.records);
}

This changes the "ALL" option to the actual number of records in the dataset.

秋风の叶未落 2024-08-05 19:19:52

设置 rowNum:-1 对我来说很有效,之后它显示了所有记录,但在网格页脚中仍然有行号选项,如下所示:

在此处输入图像描述

要删除此内容,我只需添加了一个 css 选项,通过在 jquery 中获取扇区来显示无。 像这样

$('#id_tableCell').css('display', 'none');

注意:这个css设置应该在网格加载完成时完成。

Setting rowNum:-1 works for me like, after that it was showing all records but it still has row number option in grid footer like this:

enter image description here

To remove this I just added a css option display none by getting the sector in jquery. Like this

$('#id_tableCell').css('display', 'none');

Note: This css setting should be done when the grid load is completed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文