How to get row count for jqGrid?
Asked Answered
M

6

22

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

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

But it always returns 0.

Thanks for the help.

Marlin answered 6/4, 2010 at 19:53 Comment(0)
D
37

Try:

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

from the jqGrid documentation:

reccount (integer):

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


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

Delphinedelphinia answered 6/4, 2010 at 21:19 Comment(2)
Note that if you have paging turned on in your jqGrid, this function will just return the number of rows shown on this page. To get the full row count, use the 'getGridParam' function, shown in one of the other answers.Boatswain
@MikeGledhill - Thanks, I updated this answer to include records since none of the other answers explain why that works. Note the op was not using pagination, but a lot of people reading this could be...Delphinedelphinia
L
17
jQuery("#grid").jqGrid('getGridParam', 'records');
Lobeline answered 27/9, 2011 at 14:43 Comment(0)
S
2

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

<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>
Shumate answered 12/8, 2011 at 2:36 Comment(0)
S
1

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

$("#grid").getRowData().length
Schurman answered 12/9, 2011 at 20:12 Comment(0)
B
0
<a href="javascript:void(0)" id="g9" onclick="alert(jQuery('#list').jqGrid('getGridParam','records'));">Get number of records in Grid</a>
Babby answered 9/11, 2012 at 8:6 Comment(0)
P
0

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.

//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);
Papery answered 12/5, 2016 at 8:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.