I am faced with a challenge in filtering records in a jqGrid based on multiple conditions.
For example, if there are columns for Name, Age, and City, and I need to filter the grid using the following condition:
Name = "Mark" and Age = 25 and City = 'NY'
The code below effectively filters the records-
var grid = jQuery("#memberDetails");
var postdata = grid.jqGrid('getGridParam', 'postData');
var filterArray = new Array();
var filterCondition;
filterCondition = new Object();
filterCondition.field = "name";
filterCondition.op = "eq";
filterCondition.data = "Mark";
filterArray.push(filterCondition);
filterCondition = new Object();
filterCondition.field = "Age";
filterCondition.op = "eq";
filterCondition.data = "25";
filterArray.push(filterCondition);
filterCondition = new Object();
filterCondition.field = "City";
filterCondition.op = "eq";
filterCondition.data = "NY";
filterArray.push(filterCondition);
jQuery.extend(postdata, {
filters: {
"groupOp": "and",
"rules": filterArray
}
});
grid.jqGrid('setGridParam', {
search: true,
postData: postdata
});
grid.trigger("reloadGrid", [{
page: 1
}]);
However, I am unsure how to implement the following more complex filter:
Name = "Mark" and Age = 25 and (City = 'NY' OR City = 'FL')
The groupOp
currently only supports AND or OR conditions, making it challenging to include sub-conditions within the main condition.
Any suggestions would be greatly appreciated. Thank you.