Is it possible to get all jqGrid rows across multiple pages in currently sorted order?

I am using the latest jqGrid (v4.7.1). I have a grid that is populated with local data and has multiple data pages. User sorted data on client side. Now I would like to get all rows in sorted order. Can this be done?

Here's what I know:

var data = this.ui.grid.jqGrid('getGridParam', 'data');

      

This statement returns all rows in the grid, but reverts them to their original state. Any sorting operation is independent.

var rowData = this.ui.grid.jqGrid('getRowData');

      

This statement returns all rows in the current page , but returns them in correctly sorted order.

I was thinking about taking all the data and running it through the grid sort function, but this function is heavily protected. I can access it by calling something like:

var data = this.ui.grid.jqGrid('getGridParam', 'data');
$.jgrid.from([])._doSort(data, 0)

      

However, this code still throws errors because jqGrid expects some other properties to be set before calling _doSort. I'm sure I can get this to work, but I feel like I'm hacking some code really unintentionally.

What are my options?

EDIT: This works, but pretty shitty:

var rowNum = this.ui.grid.getGridParam('rowNum');
this.ui.grid.setGridParam({ rowNum: 10000 }).trigger("reloadGrid");
var data = this.ui.grid.getRowData();
this.ui.grid.setGridParam({ rowNum: rowNum }).trigger("reloadGrid");

      

+3


source to share


1 answer


The class fields $.jgrid.from

will be used inside the jqGrid. The use of the methods is not documented. In general, you first need to create an object with $.jgrid.from

: for example, you can use

var data = $("#mygrid").jqGrid("getGridParam", "data");
var query = $.jgrid.from(data);

      

Then some internal properties of the object need to be set, like making later queries case insensitive

query = query.ignoreCase();

      

You can then sort or filter the data. For sorting, use

query.orderBy("columnNameByWhichOneSort",
    "a", // or "d" for "desc" sorting
    stype,  // sorttype from colModel oder "text"
    srcfmt, // typically ""
    sfunc); // typically null

      



For final results, use

var queryResults = query.select();

      

I recommend that you set some breakpoints inside addLocalData and debug your code. If you click on the header of the receipts column, the grid is sorted, you can see how it addLocalData

uses $.jgrid.from

internally.

Perhaps you can just follow the answer and "subclass" $.jgrid.from

. As a result, you can get full results (all pages) based on the user's sorting and search criteria.

UPDATED : free jqGrid provides an option lastSelectedData

. See the demo in the list of demos .

+3


source







All Articles