Am having issues using getLocalRow
along with data property
var $grid;
getGrid = function () {
$grid = $("list");
$grid.jqGrid({
mtype: "POST",
colNames: [],
colModel: [
....
],
pager: "",
loadonce: true,
multiselect: true,
gridComplete: function () {
var data = $(this).getDataIDs();
for(var i=0; i < data.length;i++){
$(this).setSelection(data[i]); // select all rows by default
}
},
loadComplete: function (data) {
},
loadError: function (xhr) {
}
});
return $grid;
};
There are two ways am populating the grid based on 2 scenarios.
In scenario 1, am just hitting server url and returning the data as JSON and populating in the grid. Using this option, when I iterate thru the selected rows and perform getLocalRow am getting the required o/p.
And in scenario 2, I construct a data object and pass it to the same grid. The problem occurs here when I iterate and use getLocalRow in this context am getting false for all the selected rows instead of the row data but works fine with getRowData.
scenario 1 :
$grid.jqGrid("clearGridData");
$grid.jqGrid("setGridParam", {url: '..', datatype: "json"}).trigger("reloadGrid");
scenario 2 :
$grid.jqGrid("clearGridData");
$grid("setGridParam", { data: MyOWNobject}).trigger("reloadGrid");
Accessing getLocalRow :
var sel=[];
for (i = 0; i < $grid.jqGrid("getGridParam").selarrrow.length; i++) {
sel.push($grid.jqGrid("getLocalRow", $grid.jqGrid("getGridParam").selarrrow[i]));
}
The problem is in the filling of the grid. Every row of the grid have to get unique
id
. If your data already have some column with unique data then one can usekey: true
in the column to inform jqGrid to use the value from the column as the rowid.I tested last time free jqGrid always with the data, which contains either
id
property in every column of havekey: true
property for a column which values one want use as the rowid. If you would follow the rule then the problem which you reports will not exist. See the demo http://jsfiddle.net/OlegKi/y9KHY/92/ which uses the codeThe demo http://jsfiddle.net/OlegKi/y9KHY/93/ uses
id
property in input data.Nevertheless, the usage of not full input data, without specifying rowid is allowed in general. Thus the described above behavior of free jqGrid is a bug. The bugs is fixed already in the code of free jqGrid on GitHub. You can verify it in the demo http://jsfiddle.net/OlegKi/y9KHY/94/, which uses the code directly from GitHub. I plan publish the next version soon.