Javascript 如何获取jqGrid的行数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2587817/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 01:02:39  来源:igfitidea点击:

How to get row count for jqGrid?

javascriptjqueryjqgridcountrow

提问by developer

I would like to know how to get row count for jqGrid. I'm using rowNum: -1so it displays all the rows. I tried using:

我想知道如何获取 jqGrid 的行数。我正在使用rowNum: -1它显示所有行。我尝试使用:

parseInt($("#grid").getGridParam("records"), 10)

But it always returns 0.

但它总是返回0

Thanks for the help.

谢谢您的帮助。

回答by Justin Ethier

Try:

尝试:

$("#grid").getGridParam("reccount")

from the jqGrid documentation:

来自jqGrid 文档

reccount(integer):

Readonly property. Returns the exact number of rows in the grid

记录整数):

只读属性。返回网格中的确切行数



Note also that, as Mike commented, you need to use the getGridParammethod with the recordsoption to retrieve a count of all the rows if you are using pagination.

另请注意,正如 Mike 评论的那样,如果您使用分页,则需要使用getGridParam带有records选项的方法来检索所有行的计数。

回答by dzona

jQuery("#grid").jqGrid('getGridParam', 'records');

回答by oliwa

I tried reccount and I got zero but the following worked for me.

我尝试了 reccount 并且我得到了零,但以下对我有用。

<div>Total subscriber count: <div id="count" style="display: inline;"></div></div>

<br />

<div>
    <table id="grid"></table>
</div>

<script type="text/javascript">

    $(document).ready(function () {
        $("#grid").jqGrid({
            //Other stuff removed for brevity
            gridComplete: function () {
                $('#count').html($('#grid').getGridParam('records'));
            }
        });
    });

</script>

回答by Rismo

This might be overkill and don't know if there's a better way, but this works for me:

这可能有点矫枉过正,不知道是否有更好的方法,但这对我有用:

$("#grid").getRowData().length

回答by Ashish Mehta

<a href="javascript:void(0)" id="g9" onclick="alert(jQuery('#list').jqGrid('getGridParam','records'));">Get number of records in Grid</a>

回答by ISURU

i get the grid data to array and then use the array length function to get the array length. It is equal for the number of record in the jqgrid.

我将网格数据获取到数组,然后使用数组长度函数来获取数组长度。它等于 jqgrid 中的记录数。

//get the grid data to array      
var rows = $('#jqxgrid').jqxGrid('getrows');
//  get the length of the array on array.length using javascript funcation
alert('' + rows.length);