jqgrid中的实时集成搜索工具栏

时间:2011-08-03 12:35:38

标签: jquery jqgrid

我跟着jqgrid demos(集成的搜索工具栏),但我不能让它像在演示中一样工作,在演示中,一旦用户输入一个角色,它就会触发搜索,但在我的情况下,我需要按输入然后搜索,我哪里出错?

这是我的代码

$('#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"
}

1 个答案:

答案 0 :(得分:1)

如果我理解你的错误,你应该只使用搜索工具栏的searchOnEnter: false选项。其他一些选项也可能有所帮助。我通常使用

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

并在网格中添加ignoreCase: true选项。顺便说一下,您可以将搜索工具栏与高级搜索对话框结合起来,以便构建更复杂的查询(请参阅the answer)。

相关问题