user1662458
user1662458

Reputation: 31

Retrieve all ids

How do you get all of the ids across the pages with loadonce:true and datatype:json in a jqGrid?

Upvotes: 3

Views: 1783

Answers (2)

Oleg
Oleg

Reputation: 221997

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"}
]

Upvotes: 2

Justin Ethier
Justin Ethier

Reputation: 134177

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.

Upvotes: 2

Related Questions