живая интегрированная панель инструментов поиска в jqgrid - PullRequest
0 голосов
/ 03 августа 2011

Я следовал 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 Ответ

1 голос
/ 03 августа 2011

Если я правильно понимаю, вы должны просто использовать searchOnEnter: false на панели инструментов поиска.Некоторые другие варианты также могут быть полезны.Я обычно использую

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

и добавляю к сетке опцию ignoreCase: true.Кстати, вы можете объединить панель инструментов поиска с расширенным диалоговым окном поиска, которое позволяет создавать более сложные запросы (см. ответ ).

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...