jqgrid中的实时集成搜索工具栏 [英] live integrated search toolbar in jqgrid

查看:102
本文介绍了jqgrid中的实时集成搜索工具栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我关注了 jqgrid演示(集成的搜索工具栏),但我做不到就像在演示中一样工作,在演示中,只要用户输入一个字符,它就会触发搜索,但就我而言,我需要按Enter键,然后搜索,我在哪里出错?

I followed jqgrid demos (integrated Search toolbar) but I cannot make it work like it works in the demo, In the demo as soon as the user enters a character it triggers search but in my case I need to press enter and then it searches, where am i going wrong?

这是我的代码

$('#compareContent').empty();
        $('<div id="compareParentDiv">'+
          '<table id="list2" cellspacing="0" cellpadding="0"></table>'+
                '<div id="gridpager3"></div></div>')
        .appendTo('#compareContent');

        $("#compareParentDiv").hide();

        var gridDiff = $("#list2");
        gridDiff.jqGrid({
            datastr: compareData,
            datatype: "jsonstring",
            colNames: ['KeyName', 'SubCategory', starheader, header1,'isEqual'],
            colModel: [
                { name: 'elementName', index: 'elementName', width: 150 },
                { name: 'subCategory', index: 'subCategory', width: 1 },
                { name: 'firstValue', index: 'firstValue', width: 300, jsonmap:'attribute.0.firstValue' },
                { name: 'secondValue', index: 'secondValue', width: 300,jsonmap:'attribute.0.secondValue' },
                { name: 'isEqual', index: 'isEqual', width: 1,hidden:true}
            ],

            pager: '#gridpager3',
            rowNum:50,
            scrollOffset:1,
            //viewrecords: true,

            //rownumbers: true,
            height: 320,
            autowidth:true,
            grouping: true,
            jsonReader: {
                repeatitems: false,
                page: function(){return 1;},
                root: "response"
            },

            groupingView: {
                groupField: ['subCategory'],
                groupOrder: ['desc'],
                //groupDataSorted : true,
                groupColumnShow: [false],
                //groupCollapse: true,
                //groupText: ['<b>{0} - {1} Item(s)</b>']
                groupText: ['<b>{0}</b>']
            },

            loadComplete: function() {
                if (this.p.datatype !== 'local') {
                    setTimeout(function () {
                       gridDiff.trigger('reloadGrid');
                   }, 0);
                } else {
                    $("#compareParentDiv").show();
                }

                var i, names=this.p.groupingView.sortnames[0], l = names.length;
                for (i=0;i<l;i++) {
                    if ($.inArray(names[i],grouping) >= 0) {
                        $(this).jqGrid('groupingToggle',this.id+"ghead_"+i);
                    } else {
                        // hide the grouping row
                        $('#'+this.id+"ghead_"+i).hide();
                    }
                }

                var i, l, data = this.p.data, rows = this.rows, item;
                l = data.length;
                for (i=0;i<l;i++) {
                    item = data[i];
                    if (!item.isEqual) {
                        $(rows.namedItem(item._id_))
                            .css({
                                "background-color": "#FFE3EA",
                                "background-image": "none"
                            });
                    }
                }
            }
        });
        gridDiff.jqGrid('navGrid', '#gridpager3', { add: false, edit: false, del: false, search: false, refresh: false });
        gridDiff.jqGrid('navButtonAdd',"#gridpager3",{caption:"Toggle",title:"Toggle Search Toolbar", buttonicon :'ui-icon-pin-s',
            onClickButton:function(){
                gridDiff[0].toggleToolbar();
            } 
        });
        gridDiff.jqGrid('navButtonAdd',"#gridpager3",{caption:"Clear",title:"Clear Search",buttonicon :'ui-icon-refresh',
            onClickButton:function(){
                gridDiff[0].clearToolbar();
            } 
        });
        gridDiff.jqGrid('filterToolbar');

这是我的json

{
"response": [
{
  "id": "1",
  "elementName": "bitmode",
  "category": "Product",
  "subCategory": "Product",
  "isEqual": true,
  "isPrasentinXml1": true,
  "isPrasentinXml2": true,
  "isPrasentinXml3": false,
  "attribute": [
    {
      "name": "bitmode",
      "firstValue": "file: cannot open /home/asimon/java/AIXJAVA/java/bin/libssaiok.so\u000a",
      "secondValue": "file: cannot open /home/asimon/java/AIXJAVA/java/bin/libssaiok.so\u000a"
    }
  ]
},
{
  "id": "2",
  "elementName": "connectionserver",
  "category": "Product",
  "subCategory": "IIRServers",
  "isEqual": true,
  "isPrasentinXml1": true,
  "isPrasentinXml2": true,
  "isPrasentinXml3": false,
  "attribute": [
    {
      "name": "connectionserver",
      "firstValue": "/usr/bin/sh: null/ssasvck:  not found.\u000a",
      "secondValue": "/usr/bin/sh: null/ssasvck:  not found.\u000a"
    }
  ]
},
{
  "id": "3",
  "elementName": "consoleserver",
  "category": "Product",
  "subCategory": "IIRServers",
  "isEqual": true,
  "isPrasentinXml1": true,
  "isPrasentinXml2": true,
  "isPrasentinXml3": false,
  "attribute": [
    {
      "name": "consoleserver",
      "firstValue": "/usr/bin/sh: null/ssasvck:  not found.\u000a",
      "secondValue": "/usr/bin/sh: null/ssasvck:  not found.\u000a"
    }
  ]
},
{
  "id": "4",
  "elementName": "cpuspeed",
  "category": "System",
  "subCategory": "System",
  "isEqual": true,
  "isPrasentinXml1": true,
  "isPrasentinXml2": true,
  "isPrasentinXml3": false,
  "attribute": [
    {
      "name": "cpuspeed",
      "firstValue": " 4204 \u000a",
      "secondValue": " 4204 \u000a"
    }
  ]
},
{
  "id": "5",
  "elementName": "hostname",
  "category": "System",
  "subCategory": "System",
  "isEqual": false,
  "isPrasentinXml1": true,
  "isPrasentinXml2": true,
  "isPrasentinXml3": false,
  "attribute": [
    {
      "name": "hostname",
      "firstValue": "gcslpar2\u000a",
      "secondValue": "gcslpar1\u000a"
    }
  ]
},
{
  "id": "6",
  "elementName": "httpsearchserver",
  "category": "Product",
  "subCategory": "IIRServers",
  "isEqual": true,
  "isPrasentinXml1": true,
  "isPrasentinXml2": true,
  "isPrasentinXml3": false,
  "attribute": [
    {
      "name": "httpsearchserver",
      "firstValue": "/usr/bin/sh: null/ssasvck:  not found.\u000a",
      "secondValue": "/usr/bin/sh: null/ssasvck:  not found.\u000a"
    }
  ]
},
{
  "id": "7",
  "elementName": "licenseserver",
  "category": "Product",
  "subCategory": "IIRServers",
  "isEqual": true,
  "isPrasentinXml1": true,
  "isPrasentinXml2": true,
  "isPrasentinXml3": false,
  "attribute": [
    {
      "name": "licenseserver",
      "firstValue": "/usr/bin/sh: null/ssasvck:  not found.\u000a",
      "secondValue": "/usr/bin/sh: null/ssasvck:  not found.\u000a"
    }
  ]
},
{
  "id": "8",
  "elementName": "machine",
  "category": "System",
  "subCategory": "System",
  "isEqual": true,
  "isPrasentinXml1": true,
  "isPrasentinXml2": true,
  "isPrasentinXml3": false,
  "attribute": [
    {
      "name": "machine",
      "firstValue": "000CE082D900\u000a",
      "secondValue": "000CE082D900\u000a"
    }
  ]
},
{
  "id": "9",
  "elementName": "maxfilesperproc",
  "category": "System",
  "subCategory": "Kernel Parameters",
  "isEqual": false,
  "isPrasentinXml1": true,
  "isPrasentinXml2": true,
  "isPrasentinXml3": false,
  "attribute": [
    {
      "name": "maxfilesperproc",
      "firstValue": " 2000\u000a",
      "secondValue": " 8192\u000a"
    }
  ]
},
{
  "id": "10",
  "elementName": "maxthreadsperproc",
  "category": "System",
  "subCategory": "Kernel Parameters",
  "isEqual": false,
  "isPrasentinXml1": true,
  "isPrasentinXml2": true,
  "isPrasentinXml3": false,
  "attribute": [
    {
      "name": "maxthreadsperproc"
    }
  ]
},
{
  "id": "11",
  "elementName": "mempagesize",
  "category": "System",
  "subCategory": "Kernel Parameters",
  "isEqual": true,
  "isPrasentinXml1": true,
  "isPrasentinXml2": true,
  "isPrasentinXml3": false,
  "attribute": [
    {
      "name": "mempagesize",
      "firstValue": "4096\u000a",
      "secondValue": "4096\u000a"
    }
  ]
},
{
  "id": "12",
  "elementName": "numberofcpu",
  "category": "System",
  "subCategory": "System",
  "isEqual": true,
  "isPrasentinXml1": true,
  "isPrasentinXml2": true,
  "isPrasentinXml3": false,
  "attribute": [
    {
      "name": "numberofcpu",
      "firstValue": " 2\u000a",
      "secondValue": " 2\u000a"
    }
  ]
},
{
  "id": "13",
  "elementName": "osname",
  "category": "System",
  "subCategory": "System",
  "isEqual": true,
  "isPrasentinXml1": true,
  "isPrasentinXml2": true,
  "isPrasentinXml3": false,
  "attribute": [
    {
      "name": "osname",
      "firstValue": "AIX\u000a",
      "secondValue": "AIX\u000a"
    }
  ]
},
{
  "id": "14",
  "elementName": "release",
  "category": "System",
  "subCategory": "System",
  "isEqual": true,
  "isPrasentinXml1": true,
  "isPrasentinXml2": true,
  "isPrasentinXml3": false,
  "attribute": [
    {
      "name": "release",
      "firstValue": "1\u000a",
      "secondValue": "1\u000a"
    }
  ]
},
{
  "id": "15",
  "elementName": "rulebaseserver",
  "category": "Product",
  "subCategory": "IIRServers",
  "isEqual": true,
  "isPrasentinXml1": true,
  "isPrasentinXml2": true,
  "isPrasentinXml3": false,
  "attribute": [
    {
      "name": "rulebaseserver",
      "firstValue": "/usr/bin/sh: null/ssasvck:  not found.\u000a",
      "secondValue": "/usr/bin/sh: null/ssasvck:  not found.\u000a"
    }
  ]
},
{
  "id": "16",
  "elementName": "ssaname3server",
  "category": "Product",
  "subCategory": "IIRServers",
  "isEqual": true,
  "isPrasentinXml1": true,
  "isPrasentinXml2": true,
  "isPrasentinXml3": false,
  "attribute": [
    {
      "name": "ssaname3server",
      "firstValue": "/usr/bin/sh: null/ssasvck:  not found.\u000a",
      "secondValue": "/usr/bin/sh: null/ssasvck:  not found.\u000a"
    }
  ]
},
{
  "id": "17",
  "elementName": "ssaname3webserviceserver",
  "category": "Product",
  "subCategory": "IIRServers",
  "isEqual": false,
  "isPrasentinXml1": true,
  "isPrasentinXml2": true,
  "isPrasentinXml3": false,
  "attribute": [
    {
      "name": "ssaname3webserviceserver",
      "firstValue": "/usr/bin/sh: null/ssasvck:  not found.\u000a",
      "secondValue": "/usr/bin/sh: null/ssasvck:  not found.\u000a"
    }
  ]
},
{
  "id": "18",
  "elementName": "version",
  "category": "System",
  "subCategory": "System",
  "isEqual": true,
  "isPrasentinXml1": true,
  "isPrasentinXml2": true,
  "isPrasentinXml3": false,
  "attribute": [
    {
      "name": "version",
      "firstValue": "6\u000a",
      "secondValue": "6\u000a"
    }
  ]
},
{
  "id": "19",
  "elementName": "xmlconsoleserver",
  "category": "Product",
  "subCategory": "IIRServers",
  "isEqual": true,
  "isPrasentinXml1": true,
  "isPrasentinXml2": true,
  "isPrasentinXml3": false,
  "attribute": [
    {
      "name": "xmlconsoleserver",
      "firstValue": "/usr/bin/sh: null/ssasvck:  not found.\u000a",
      "secondValue": "/usr/bin/sh: null/ssasvck:  not found.\u000a"
    }
  ]
},
{
  "id": "20",
  "elementName": "xmlsearchserver",
  "category": "Product",
  "subCategory": "IIRServers",
  "isEqual": true,
  "isPrasentinXml1": true,
  "isPrasentinXml2": true,
  "isPrasentinXml3": false,
  "attribute": [
    {
      "name": "xmlsearchserver",
      "firstValue": "/usr/bin/sh: null/ssasvck:  not found.\u000a",
      "secondValue": "/usr/bin/sh: null/ssasvck:  not found.\u000a"
    }
  ]
},
{
  "id": "21",
  "elementName": "xmlsyncserver",
  "category": "Product",
  "subCategory": "IIRServers",
  "isEqual": true,
  "isPrasentinXml1": true,
  "isPrasentinXml2": true,
  "isPrasentinXml3": false,
  "attribute": [
    {
      "name": "xmlsyncserver",
      "firstValue": "/usr/bin/sh: null/ssasvck:  not found.\u000a",
      "secondValue": "/usr/bin/sh: null/ssasvck:  not found.\u000a"
    }
  ]
}
],
"xls_path": "\\csm\\files\\comparefiles\\compare_output.xls"
}

推荐答案

如果我了解您的要求,您应该使用

If I understand you correct you should just use searchOnEnter: false option of the searching toolbar. Some other options could be also helpful. I use typically

gridDiff.jqGrid('filterToolbar',
    {stringResult: true, searchOnEnter: true, defaultSearch: 'cn'});

,并在网格中另外添加ignoreCase: true选项.顺便说一下,您可以将搜索工具栏与高级搜索对话框结合使用,从而可以构造更复杂的查询(请参见

and add additionally ignoreCase: true option to the grid. By the way you can combine the searching toolbar with advanced searching dialog which allows to construct more complex queries (see the answer).

这篇关于jqgrid中的实时集成搜索工具栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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