Hi Abu
I need an help.
I have 2 autonomous grids.
Although both grids are autonomous these have a column with similar values
I would that when I click a row in the 1st grid this column value functions as a filter in the 2nd grid and viceversa.
To do this I add this in the 1st grid:
$e["js_on_select_row"] = "do_onselect_purchase_document";
…
function do_onselect_purchase_document() {
var cn = $("#list1").jqGrid('getCell', selr, 'LinkedDocument');
f = {groupOp:"AND",rules:[]};
var searchFiler = cn, grid = $("#list2"), f;
if (searchFiler.length === 0) {
grid[0].p.search = false;
$.extend(grid[0].p.postData,{filters:""});
}
f.rules.push({field:"LinkedDocument",op:"cn",data:searchFiler});
grid[0].p.search = true;
$.extend(grid[0].p.postData,{filters:JSON.stringify(f)});
$("#list2").trigger("reloadGrid",[{page:1,current:true}]);
and this in the 2nd
$e["js_on_select_row"] = "do_onselect_sale_document";
…
function do_onselect_sale_document() {
…
var cn = $("#list2").jqGrid('getCell', selr, 'LinkedDocument');
f = {groupOp:"AND",rules:[]};
var searchFiler = cn, grid = $("#list1"), f;
if (searchFiler.length === 0) {
grid[0].p.search = false;
$.extend(grid[0].p.postData,{filters:""});
}
f.rules.push({field:"LinkedDocument",op:"cn",data:searchFiler});
grid[0].p.search = true;
$.extend(grid[0].p.postData,{filters:JSON.stringify(f)});
$("#list1").trigger("reloadGrid",[{page:1,current:true}]);
Unfortunately sometimes this solution is looped.
Any suggestion?
Thanks in advance
Your code looks fine.
If your solution is online, share the link or email me at [email protected]
Hi Abu,
I solved with the method resetSelection()
This is the code rivisited:
1st grid:
function do_onselect_document_purchese(id) {
var grid = $("#list1");
var selr = grid.jqGrid('getGridParam', 'selrow');
if (selr > 0) {
var cn = $("#list1").jqGrid('getCell', selr, 'LinkedDocument');
$("#list1").resetSelection();
f = {rules:[]};
searchFiler = cn, grid = $("#list2"), f;
f.rules.push({field:"LinkedDocument",op:"cn",data:searchFiler});
grid[0].p.search = true;
$.extend(grid[0].p.postData,{filters:JSON.stringify(f)});
$("#list2").trigger("reloadGrid",[{page:1,current:true}]);
}
}
2nd grid:
function do_onselect_documento_sale(id) {
var grid = $("#list2");
var selr = grid.jqGrid('getGridParam', 'selrow');
if (selr > 0) {
var cn = $("#list2").jqGrid('getCell', selr, 'LinkedDocument');
$("#list2").resetSelection();
f = {rules:[]};
searchFiler = cn, grid = $("#list1"), f;
f.rules.push({field:"LinkedDocument",op:"cn",data:searchFiler});
grid[0].p.search = true;
$.extend(grid[0].p.postData,{filters:JSON.stringify(f)});
$("#list1").trigger("reloadGrid",[{page:1,current:true}]);
}
}