How do you get all of the ids across the pages with loadonce:true and datatype:json in a jqGrid?
            Asked
            
        
        
            Active
            
        
            Viewed 1,771 times
        
    3
            
            
        
        CharlesB
        
- 86,532
 - 28
 - 194
 - 218
 
        user1662458
        
- 31
 - 2
 
2 Answers
2
            
            
        You can use the data option to retrieve the grid data directly:
 myGrid.jqGrid('getGridParam', 'data');
Then you would need to iterate over data to retrieve each of your ID's.
        Justin Ethier
        
- 131,333
 - 52
 - 229
 - 284
 
2
            
            
        You need get _index parameter of jqGrid. It's object having ids as properties. If you need to have an array of ids (like with getDataIDs method) you can do the following
var id, ids = [], indexes = $("#grid").jqGrid("getGridParam", "_index");
for (id in indexes) {
    if (indexes.hasOwnProperty(id)) {
        ids.push(id);
    }
}
The code fills the ids array with the ids of the local grid.
By the way the value of the _index object (like indexes[id] in the for loop above) contains the index of the corresponding data object in the $("#grid").jqGrid("getGridParam", "data") array.
For example if you will fill the grid with the data like
var myData = [
        {id: "x", name: "abc", age: "12"},
        {id: "y", name: "def", age: "34"}
    ];
$("#grid").jqGrid({
    data: myData,
    datatype: "local",
    colModel: [{name: "name"}, {name: "age"}]
});
then the $("#grid").jqGrid("getGridParam", "_index") will be object
{
    x: 0, // index of the data for the item having id="x"
    y: 1  // index of the data for the item having id="y"
}
and $("#grid").jqGrid("getGridParam", "data") will be array
[
    {name: "abc", age: "12"}
    {name: "def", age: "34"}
]
        Oleg
        
- 220,925
 - 34
 - 403
 - 798