jqGrid在提交时更改搜索过滤器 [英] jqGrid change search filters on submit

查看:139
本文介绍了jqGrid在提交时更改搜索过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用户提交搜索过滤器后对其进行更改.通常,jqGrid在colmodel中将name作为字段的value返回,我想针对特定列更改此行为:

I would like to alter the search filters after a user has submitted them. Normally jqGrid returns name in colmodel as the value for field, I would like to change this behavior for a specific column:

我想更改:

{"groupOp":"AND","rules":[{"field":"available","op":"eq","data":"true"}]}

{"groupOp":"AND","rules":[{"field":"s.trait.available","op":"eq","data":"true"}]}

我尝试过以下方式更改提交的表格;萤火虫显示这些功能从未被调用过.

I have tried altering the submitted form in the ways below; firebug shows that the functions are never being called.

var searchOptions = {
        multipleSearch:true, multipleGroup:false, closeOnEscape:true, closeAfterSearch:true,
        sopt:['ge', 'eq', 'le'],
    beforeSubmit:function (params, postdata) {
        //alterations would be here
    }
    ,
    onclickSubmit:function (params, postdata) {
        //alterations would be here
    }
}

这种方法适用于editOptions和delOptions,但我不确定为什么无法使它在搜索中起作用.

This approach works for editOptions and delOptions, I am not sure why I cannot get this to work for searching.

推荐答案

如果使用搜索工具栏,则可以使用 onSearch .

If you use the searching toolbar you can use beforeSearch callback to modify the postData.filter. In case of Singe Field searching or Advanced Searching you can use onSearch.

答案中,您可以看到如何修改postData.filter.

In the answer you can see how the postData.filter can be modified.

已更新:您在测试中做错了什么.唯一的问题是,当前的搜索实现方式并未将this初始化为网格,但未在某处明确记录.

UPDATED: You did something wrong in your tests. The only problem is that the current implementation of searching don't initialize this to the grid, but it's not explicitly documented somewhere.

我为您创建了演示,该演示演示了您所做的可以在开始重新网格划分之前修改过滤器.如果您在网格中搜索等于300的客户",则搜索请求将被修改为等于300的金额",您将看到结果

I created the demo for you which demonstrate that you do can modify the filter before relaoding of the grid will be started. If you would search in the grid for 'Client' equal to 300 the search request will be modified to 'amount' equal to 300 and you would see the results

对应的代码是

$('#list').jqGrid('navGrid', '#pager', {add: false, edit: false, del: false}, {}, {}, {},
    {
        multipleSearch: true,
        overlay: 0,
        onSearch: function () {
            var i, l, rules, rule, $grid = $('#list'),
                postData = $grid.jqGrid('getGridParam', 'postData'),
                filters = $.parseJSON(postData.filters);

            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.field === 'name') {
                        // make modifications only for the 'contains' operation
                        rule.field = 'amount';
                    }
                }
                postData.filters = JSON.stringify(filters);
            }
        }});

这篇关于jqGrid在提交时更改搜索过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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