在客户端通过多个条件过滤jqGrid [英] Filtering jqGrid by multiple conditions at client side

查看:135
本文介绍了在客户端通过多个条件过滤jqGrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a jqGrid with some records and want to filter the records based on multiple conditions.

例如,如果有三列,名称,年龄和城市我想在以下条件下过滤网格:

For instance, if there are three columns, Name, Age and City and I want to filter the grid on the following condition:

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

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

but I am not sure how to make the following filter work:

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

groupOp 在AND条件下工作,或者在OR条件下工作,不知道如何嵌入子条件在 groupOp

The groupOp works either on AND or on OR condition, not sure how to embed a sub condition within the groupOp

谢谢。

推荐答案

<$ href =http://www.trirand.com/jqgridwiki/doku.php?id=中描述了过滤器的格式wiki:advanced_searching#optionsrel =nofollow>文档。要实现更复杂的搜索条件,可以使用 groups 属性过滤器。相应的代码可以是以下内容:

Format of filters are described in the documentation. To implement more complex searching criteria one can use groups property of filters. The corresponding code could be about the following:

var $grid = $("#memberDetails");

$.extend($grid.jqGrid("getGridParam", "postData"), {
    filters: JSON.stringify({
        groupOp: "AND",
        rules: [
            { field: "Name", op: "eq", data: "Mark" },
            { field: "Age",  op: "eq", data: "25" }
        ],
        groups: [
            {
                groupOp: "OR",
                rules: [
                    { field: "City", op: "eq", data: "NY" },
                    { field: "City", op: "eq", data: "FL" }
                ],
                groups: []
            }
        ]
    })
});
$grid.jqGrid("setGridParam", {search: true})
     .trigger('reloadGrid', [{current: true, page: 1}]);

这篇关于在客户端通过多个条件过滤jqGrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆