1

我需要帮助来使用过滤器工具栏下拉菜单对 jqgrid 数据进行范围选择 - 我检查了它只有的 sopt 选项 -

['equal','not equal', 'less', 'less or equal','greater','greater or equal', 'begins with','does not begin with','is in','is not in','ends with','does not end with','contains','does not contain']

而且我无法在工具栏上找到有关如何使用此范围进行范围的任何线索。我有一个下拉菜单,其中包含"All", "1-4", "5-9"我的过滤器工具栏上的值,当我选择说'1-4'我希望网格填充该范围内的所有行时。我查看了一堆来自 stackoverflow 和 trirand 本身的过滤器示例,但它们似乎都用于搜索框。我很感激任何帮助来实现这一点,谢谢。

4

1 回答 1

0

我能够根据示例多词样本- http://www.ok-soft-gmbh.com/jqGrid/MultiwordSearchingToolbar.htm按范围实现此过滤器。大部分代码来自上述示例,并进行了细微更改。根据 Oleg 的反馈进行了修改,使其成为 le 和 ge。

    modifySearchingFilter = function (separator) {
            var i, rules, rule, parts, group, str;
            var filters = $.parseJSON(this.p.postData.filters); 
            if(separator != '-')
              return;
            if (filters && typeof filters.rules !== 'undefined' && filters.rules.length > 0) {
                rules = filters.rules;
                for (i = 0; i < rules.length; i++) {
                    rule = rules[i];
                    if (rule.op === 'range') {
                        // Range should only have 2 parts lowerbound and upperbound
                        parts = rule.data.split(separator);
                        if (parts.length == 2) {
                            if (typeof filters.groups === 'undefined') {
                                    filters.groups = [];
                            }
                            group = {
                                groupOp: 'AND',
                                groups: [],
                                rules: []
                            };
                            filters.groups.push(group);
                            // Breaking to 2 rules one le and other ge
                            group.rules.push({
                                        data: (parts[0]),
                                        op: "ge",
                                        field: rule.field
                                    });                             
                            group.rules.push({
                                        data: (parts[1]),
                                        op: "le",
                                        field: rule.field
                                    });                                                                     
                            rules.splice(i, 1);     
                            i--; // to skip i++                             
                        }
                    }
                }
                this.p.postData.filters = JSON.stringify(filters);
            }
        },


 //using range op so that it is not confused with other ops
 setRangeSearchSelect = function(columnName) {
        grid.jqGrid('setColProp', columnName,
        {
           stype: 'select',
           searchoptions: {                                 value:buildRangeSearchSelect(),
                 sopt:['range'],                            
        }
     });
    };

 grid.jqGrid('filterToolbar',  
    {
     stringResult:true, 
     searchOnEnter:true,      
     defaultSearch:"cn", 
     beforeSearch: function () {  
       modifySearchingFilter.call(this, '-');    
     }});
于 2012-06-11T07:07:09.773 回答