在客户端通过多个条件过滤jqGrid

时间:2012-11-06 07:04:21

标签: javascript jqgrid

我有一个带有一些记录的jqGrid,并希望根据多个条件过滤记录。

例如,如果有三列,Name,Age和City,我想在以下条件下过滤网格:

Name = "Mark" and Age = 25 and City = 'NY'

以下代码正常 -

 var grid = jQuery("#memberDetails");
 var postdata = grid.jqGrid('getGridParam', 'postData');

 var filterArray = new Array();
 var filterConidtion; 

 filterConidtion = new Object();
 filterConidtion.field = "name";
 filterConidtion.op = "eq";
 filterConidtion.data = "Mark";
 filterArray.push(filterConidtion);

 filterConidtion = new Object();
 filterConidtion.field = "Age";
 filterConidtion.op = "eq";
 filterConidtion.data = "25";
 filterArray.push(filterConidtion);

 filterConidtion = new Object();
 filterConidtion.field = "City";
 filterConidtion.op = "eq";
 filterConidtion.data = "NY";
 filterArray.push(filterConidtion);

 jQuery.extend(postdata, {
        filters: {
            "groupOp": "and",
            "rules": filterArray
        }
    });

 grid.jqGrid('setGridParam', {
            search: true,
            postData: postdata
    });

 grid.trigger("reloadGrid", [{
        page: 1
    }]);

但我不确定如何使以下过滤器工作:

Name = "Mark" and Age = 25 and (City = 'NY' OR City = 'FL')

groupOp在AND或OR条件下工作,不确定如何在groupOp

中嵌入子条件

感谢。

1 个答案:

答案 0 :(得分:5)

the documentation中描述了filters的格式。要实现更复杂的搜索条件,可以使用groups的{​​{1}}属性。相应的代码可以是以下内容:

filters