有没有一种方法可以自定义jqGrid中特定列的搜索规则? [英] Is there a way to customize search rules in jqGrid in particular column?

查看:125
本文介绍了有没有一种方法可以自定义jqGrid中特定列的搜索规则?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有jqgrid:

    jQuery("#list").jqGrid( {
            url : 'ajax/get',
            datatype : 'json',
            mtype : 'POST',
            colNames : [
                'Date',
                'ID'
            ],
            colModel : [{
                    name : 'date',
                    index : 'date',
                    width : 60,
              align : 'center',
                    searchoptions:{sopt:['gt', 'lt']}
                },{
                    name : 'id',
                    index : 'id',
                    width : 40,
              align : 'center',
                    searchoptions:{sopt:['eq']}
                }]
   //.......
        });

是否可以在日期"列中设置"odata"选项.现在显示更大"和更少".我需要-从"和到".

Is there a way to set "odata" option in "Date" column. Now it's showing "greater" and "less". I need - "from" and "to".

我尝试这个:

colModel : [{
                    name : 'date',
                    index : 'date',
                    width : 60,
                    align : 'center',
                    searchoptions:{sopt:['gt', 'lt'], odata:['from', 'to']}
                }

它不起作用,仍然显示更大"和更少".试过这个:

It's not working, still showing "greater" and "less". Tried this :

$(document).ready(function(){
  $.jgrid.search = {
    odata : ['equal','not equal', 'to', 'less or equal','from','greater or equal', 'begins with','does not begin with','is in','is not in','ends with','does not end with','contains','does not contain']
  };
  $.extend($.jgrid.search);
});

它在所有列中将更大"替换为从",将更少"替换为到",但是我只需要在日期"列中.有办法吗?

It's replaces "greater" to "from" and "less" to "to" in all columns, but I need only in "Date" column. Is there a way to do it?

谢谢.

推荐答案

我遇到了类似的问题,最终通过编辑一些jqGrid源代码解决了这个问题.

I had a similar problem and ended up solving it by editing some of the jqGrid source code.

我在ops数组中添加了其他运算符. (在4.4.0版中为6130行.)

I added additional operators to the ops array. (It was line 6130 in version 4.4.0.)

ops : [
    {"name": "eq", "description": "equal", "operator":"="},
    {"name": "ne", "description": "not equal", "operator":"<>"},
    {"name": "lt", "description": "less", "operator":"<"},
    {"name": "le", "description": "less or equal","operator":"<="},
    {"name": "gt", "description": "greater", "operator":">"},
    {"name": "ge", "description": "greater or equal", "operator":">="},
    {"name": "bw", "description": "begins with", "operator":"LIKE"},
    {"name": "bn", "description": "does not begin with", "operator":"NOT LIKE"},
    {"name": "in", "description": "in", "operator":"IN"},
    {"name": "ni", "description": "not in", "operator":"NOT IN"},
    {"name": "ew", "description": "ends with", "operator":"LIKE"},
    {"name": "en", "description": "does not end with", "operator":"NOT LIKE"},
    {"name": "cn", "description": "contains", "operator":"LIKE"},
    {"name": "nc", "description": "does not contain", "operator":"NOT LIKE"},
    {"name": "nu", "description": "is null", "operator":"IS NULL"},
    {"name": "nn", "description": "is not null", "operator":"IS NOT NULL"},
    {"name": "to", "description": "to", "operator":"<"},
    {"name": "fr", "description": "from", "operator":">"}
    ],
numopts :  
    ['eq','ne','lt','le','gt','ge','nu','nn','in','ni'],
stropts :
    ['eq','ne','bw','bn','ew','en','cn','nc','nu','nn','in', 'ni','to','fr'],

在日期列规范的sopt参数中使用这些新选项. (您可能还需要根据搜索结果的实现来调整后端以翻译这些运算符.)

Use these new options in the sopt parameter in your date column specification. (You may also need to adjust the back end to translate these operators depending on your search results implementation.)

{name:'mydatefield', searchoptions: {sopt:['to', 'fr']}}

希望这会有所帮助.

这篇关于有没有一种方法可以自定义jqGrid中特定列的搜索规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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