jquery filters for two grids

Questionsjquery filters for two grids
Massimo Gagliardi asked 8 years ago

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

2 Answers
Abu Ghufran answered 8 years ago

Your code looks fine.
If your solution is online, share the link or email me at [email protected]

Massimo Gagliardi answered 8 years ago

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}]);
}
}

Your Answer

6 + 6 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?