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

查看:24
本文介绍了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"}]}

我已尝试通过以下方式更改提交的表单;firebug 显示函数从未被调用.

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.

推荐答案

如果你使用搜索工具栏,你可以使用 beforeSearch 回调修改postData.filter.如果是单字段搜索或高级搜索,您可以使用 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.

我为您创建了 演示,以证明您确实做到了可以在重新加载网格之前修改过滤器.如果您在网格中搜索 'Client' 等于 300,则搜索请求将被修改为 'amount' 等于 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天全站免登陆