One can see at least two important problem in the code of abc
function.
The first one is the usage of setGridParam
before JQuery("#table2").jqGrid({...});
which creates the grid. You can't use setGridParam
on the <table>
. The call like JQuery("#table2").jqGrid({...});
converts empty <table id="table2"></table>
element in relatively complex structure of dives and tables which will be used to display the grid. So you should first create the grid (covert empty <table>
to the grid) and only after it you can use setGridParam
or .trigger("reloadGrid")
to refresh grid content.
The second problem is the usage of JQuery("#table2").jqGrid({...});
inside of function abc
which you call multiple times. As I described before the call JQuery("#table2").jqGrid({...});
coverts empty <table>
to the grid. So one can make such call only once. For the second loading of the grid you should just use setGridParam
and .trigger("reloadGrid")
to refresh grid content.
UPDATED: If you want implement master/details scenario you can do following:
// create master grid
$("#table1").jqGrid({
datatype: "json",
url: "masterGridUrl",
onSelectRow: function (rowid, state) {
if (state) { // if not the same row was previously selected
// refresh detail grid
$("#table2").jqGrid("setGridParam", { datatype: "json"})
.trigger("reloadGrid", [{page: 1}]);
}
},
... // another options
});
// create details grid without filling the data initially
$("#table2").jqGrid({
datatype: "json", // we use "local" instead of "json" to have to request to the server
url: "JGridA",
postData: {
action: "abc",
hidden: function () {
// id of currently selected row
return $("#table1").jqGrid("getGridParam", "selrow");
}
},
... // other options
});
It will create master grid "#table1" and empty detail grid "#table2". After selection of row in the master grid the body of detail grid will be reloaded. Detail grid send to the server two additional parameters: one static parameter action=abc
and another parameter hidden
which value is the rowid of the master grid.
If you use navGrid
in the master grid you can add beforeRefresh
callback (see the answer for the code example). In the beforeRefresh
callback of master grid you can call clearGridData
for the detail grid. So if you would refresh the master grid the detail grid will be empty till the row in the master grid will be selected.