jqGrid getData only returns data for current page
Asked Answered
A

2

9

Hopefully this is a quick one!

I have an editable grid using 'clientSide' (local) data and I now wish to iterate all the rows in javascript and process/package the data myself before sending it to the server via a jQuery.ajax call.

The problem is that, unexpectedly (for me at least), using the following code only retrieves the rows for the currently visible grid page! How can I get ALL the rows in the grid (i.e. I have four pages of 10 records each and this code only returns the first 10 when I'm on page 1)? They must be present in the client somewhere because I can page around and edit the rows and the data is persisted without calling the server! :)

    cacheCONF = [];
    var rows= $('#myGrid').getRowData();  //<--Need to get ALL rows here!!!
    var cacheRowID = 0;
    for (var row in rows) {
        if (rows[row].Action == 'Yes') {
            cacheCONF.push({ RowID: rowID, System: rows[row].System, Action: rows[row].Action, Account: '-', Required: '-'  });
            rowID++;
        }
    }
Apollo answered 22/7, 2010 at 8:53 Comment(1)
Found a workaround by temporarily changing the page size. Hope there's a more "formal" solution. Code is: var pageSize = $('#myGrid').getGridParam('rowNum'); $('#myGrid').setGridParam({ rowNum: 10000 }).trigger("reloadGrid"); getRowData will then get up to 10000 rows (so set it higher than yuor max possible rows). You can then use pageSize to set the page size back to the user's preference.Apollo
A
8

Solution from Tony:

var mydata = $("#grid").jqGrid('getGridParam','data');
Apollo answered 22/7, 2010 at 13:30 Comment(2)
But this will not return the right sorting order of the data when sorting then calling that function, is there any other function for it?Dandy
Nice answer. Only issue is if you have formatted data with formatter functions within JQGrid while loading the table, those new values will be lost.Graphomotor
C
5

Had encountered a similar problem, below is what I ended up using

var data = $("#table-id").jqGrid('getGridParam', 'data');
for (var i = 0; i < data.length; i++) {
    var f_name = data[i].FirstName;
    var l_name = data[i].LastName;
    // blah... blah..
}

Reference : http://www.trirand.com/blog/?page_id=393/help/jqgrid-getdata-only-returns-data-for-current-page/

Caper answered 2/1, 2013 at 12:29 Comment(1)
Your solution worked for me. getRowData() was not returning the last row of the grid for some reason.Myotonia

© 2022 - 2024 — McMap. All rights reserved.