在multiplesearch jqGrid中删除搜索运算符(AND/OR) [英] Remove search operator (AND/OR) in multiplesearch jqGrid

查看:25
本文介绍了在multiplesearch jqGrid中删除搜索运算符(AND/OR)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在搜索弹出窗口中隐藏运算符,但我无法让它工作.我试过了,但两个运算符仍然出现:

I need to hide the operator in the search popup, but I cannot get it to work. I tried this, but both operators still appear:


jQuery("#grilla").navGrid("#paginador",
{del:false,add:false,edit:false},{},{},{},{
groupOps: [{ op: "OR", text: "any" }], multipleSearch:true});

有什么想法吗?谢谢!

推荐答案

没有选项可以直接做你需要的.此外,如果您要在对话框初始化时从搜索对话框中隐藏 ADD/OR 操作数(例如在 beforeShowSearch 事件处理程序) 与 $('select.opsel').hide() 选择元素将被隐藏仅在开头.用户单击任何按钮后,对话框包含将被重新绘制,而无需调用任何事件处理程序,并且选择元素将再次可见.

There are no option which can directly do what you need. Moreover if you would hide the ADD/OR operand from the searching dialog at the dialog initialization (for example inside of beforeShowSearch event handler) with $('select.opsel').hide() the select element will be hidden only at the beginning. After the user click on any button the dialog contain will be repaint without calling of any event handler and the select element will be again visible.

所以我建议通过覆盖方法来解决问题 reDraw.执行此操作的代码如下所示

So I suggest to solve the problem with overwriting the method reDraw of the filter dialog. The code which do this can look like

jQuery("#grilla").jqGrid("navGrid","#paginador",
    {del: false, add: false, edit: false}, {}, {}, {},
    {
        multipleSearch: true,
        beforeShowSearch: function($form) {
            var searchDialog = $form[0],
                oldrReDraw = searchDialog.reDraw, // save the original reDraw method
                doWhatWeNeed = function () {
                    // hide the AND/OR operation selection
                    $('select.opsel', searchDialog).hide();

                    setTimeout(function () {
                       // set fucus in the last input field
                       $('input[type="text"]:last', searchDialog).focus();
                    }, 50);
                }
            searchDialog.reDraw = function () {
                oldrReDraw.call(searchDialog);    // call the original reDraw method
                doWhatWeNeed();
            }
            doWhatWeNeed();
        }
    }
);

您可以在 演示上看到这种方法确实有效.

You can see on the demo that the way really works.

更新:写完答案后,我向 trirand 提出了一些改进 jqGrid 的建议.现在 jqGrid 有许多功能可以简化上述工作.例如存在可以直接使用的 afterRedraw 回调.所以答案中的代码看起来像

UPDATED: After writing of the answer I posted some suggestions to trirand to improve jqGrid. Now jqGrid has many features which simplify the above work. For example there are exist afterRedraw callback which can be directly used. So the code from the answer will look like

grid.jqGrid("navGrid", "#pager",
    {add: false, edit: false, del: false}, {}, {}, {},
    {
        multipleSearch: true,
        afterRedraw: function (p) {
            var $form = $(this);
            $form.find("select.opsel").hide();
            setTimeout(function () {
               // set fucus in the last input field
               $form.find('input[type="text"]:last').focus();
            }, 50);
            $form.find("input.add-rule,input.delete-rule").button();
        }
    }
);

查看修改后的演示这里:

我在afterRedraw

$form.find("input.add-rule,input.delete-rule").button();

仅用于改善搜索对话框中按钮的外观.我建议在 jqGrid 中将此类设置设为默认值,但这并未被 trirand 接受.无论如何,每个包含 jQuery UI 的人都可以在 afterRedraw 中添加这样的行来使按钮变平.

only to improve the look of buttons in the Searching Dialog. I suggested to make such settings default in jqGrid, but this was not accepted by trirand. In any way everyone who includes jQuery UI can add such line in afterRedraw to make the buttons flat.

这篇关于在multiplesearch jqGrid中删除搜索运算符(AND/OR)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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