有没有办法在 jqGrid 的特定列中自定义搜索规则?

发布于 2024-09-11 02:11:50 字数 1479 浏览 8 评论 0原文

我有 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”选项。现在它显示“更大”和“更少”。我需要 - “从”和“到”。

我尝试这个:

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

它不起作用,仍然显示“更大”和“更少”。尝试过这个:

$(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);
});

它将所有列中的“更大”替换为“从”,将“更少”替换为“到”,但我只需要在“日期”列中。有办法做到吗?

谢谢。

I have 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']}
                }]
   //.......
        });

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

I try this :

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?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

暮色兮凉城 2024-09-18 02:11:50

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

我向 ops 数组添加了额外的运算符。 (这是版本 4.4.0 中的第 6130 行。)

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 参数中使用这些新选项。 (您可能还需要根据您的搜索结果实现调整后端来翻译这些运算符。)

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

希望这会有所帮助。

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

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'],

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']}}

Hope this helps.

心碎无痕… 2024-09-18 02:11:50

要在 jqGrid 中使用搜索,您可以调用 navGrid 函数来添加带有搜索按钮的导航器。函数 navGrid 将对象作为第 6 个参数(请参阅 http://www.trirand.com/jqgridwiki/doku.php?id=wiki:navigator#definition),可用于覆盖 $ 中的任何默认参数。 jgrid.search 包含 odata 参数。所以你可以做类似以下的事情

jQuery("#list").jqGrid('navGrid','#pager',{search:true},{},{},{},
                {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']});

To use searching in jqGrid you call probably navGrid function to add navigator with the search button. The function navGrid has as the 6-th parameter an object (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:navigator#definition) which can be used to overwrite any default parameters from $.jgrid.search inclusive odata parameter. So you can do something like following

jQuery("#list").jqGrid('navGrid','#pager',{search:true},{},{},{},
                {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']});
十六岁半 2024-09-18 02:11:50
  1. jqGrid 版本 4.5.4
  2. JQuery 版本 1.9.0(包含在 jqGrid Zip 文件中)
  3. Chrome 版本 31.0.1650.48 m

Chrome 31.x 的 Jquery 1.9/1.10 中存在一个问题:event.returnValue 已弃用。请改用标准的 event.preventDefault() 。 http://bugs.jquery.com/ticket/14320

替换以下代码 (JQuery 2. x 版本)=>删除 src.returnValue

    // Events bubbling up the document may have been marked as prevented
    // by a handler lower down the tree; reflect the correct value.
    this.isDefaultPrevented = (src.defaultPrevented ||
    src.getPreventDefault && src.getPreventDefault()) ? returnTrue : returnFalse;

可以为我工作

  1. jqGrid Version 4.5.4
  2. JQuery Version 1.9.0 (included in jqGrid Zip File)
  3. Chrome Version 31.0.1650.48 m

There is a Problem in Jquery 1.9/1.10 with Chrome 31.x : event.returnValue is deprecated. Please use the standard event.preventDefault() instead. http://bugs.jquery.com/ticket/14320

Replace the following code (JQuery 2.x version) => remove src.returnValue

    // Events bubbling up the document may have been marked as prevented
    // by a handler lower down the tree; reflect the correct value.
    this.isDefaultPrevented = (src.defaultPrevented ||
    src.getPreventDefault && src.getPreventDefault()) ? returnTrue : returnFalse;

can work for me

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文