barre de recherche intégrée en direct dans jqgrid

J’ai suivi les démonstrations de jqgrid (barre d’outils de recherche intégrée) mais je ne peux pas le faire fonctionner comme si cela fonctionnait dans la démo. Dans la démo dès que l’utilisateur saisit un caractère, il déclenche la recherche mais dans mon cas, je dois appuyer sur entrée, puis il recherche, Où vais-je mal?

Voici mon code

$('#compareContent').empty(); $('
'+ '
'+ '
') .appendTo('#compareContent'); $("#compareParentDiv").hide(); var gridDiff = $("#list2"); gridDiff.jqGrid({ datastr: compareData, datatype: "jsonssortingng", 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:'atsortingbute.0.firstValue' }, { name: 'secondValue', index: 'secondValue', width: 300,jsonmap:'atsortingbute.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: ['{0} - {1} Item(s)'] groupText: ['{0}'] }, loadComplete: function() { if (this.p.datatype !== 'local') { setTimeout(function () { gridDiff.sortinggger('reloadGrid'); }, 0); } else { $("#compareParentDiv").show(); } var i, names=this.p.groupingView.sortnames[0], l = names.length; for (i=0;i= 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');

Voici mon json

 { "response": [ { "id": "1", "elementName": "bitmode", "category": "Product", "subCategory": "Product", "isEqual": true, "isPrasentinXml1": true, "isPrasentinXml2": true, "isPrasentinXml3": false, "atsortingbute": [ { "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, "atsortingbute": [ { "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, "atsortingbute": [ { "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, "atsortingbute": [ { "name": "cpuspeed", "firstValue": " 4204 \u000a", "secondValue": " 4204 \u000a" } ] }, { "id": "5", "elementName": "hostname", "category": "System", "subCategory": "System", "isEqual": false, "isPrasentinXml1": true, "isPrasentinXml2": true, "isPrasentinXml3": false, "atsortingbute": [ { "name": "hostname", "firstValue": "gcslpar2\u000a", "secondValue": "gcslpar1\u000a" } ] }, { "id": "6", "elementName": "httpsearchserver", "category": "Product", "subCategory": "IIRServers", "isEqual": true, "isPrasentinXml1": true, "isPrasentinXml2": true, "isPrasentinXml3": false, "atsortingbute": [ { "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, "atsortingbute": [ { "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, "atsortingbute": [ { "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, "atsortingbute": [ { "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, "atsortingbute": [ { "name": "maxthreadsperproc" } ] }, { "id": "11", "elementName": "mempagesize", "category": "System", "subCategory": "Kernel Parameters", "isEqual": true, "isPrasentinXml1": true, "isPrasentinXml2": true, "isPrasentinXml3": false, "atsortingbute": [ { "name": "mempagesize", "firstValue": "4096\u000a", "secondValue": "4096\u000a" } ] }, { "id": "12", "elementName": "numberofcpu", "category": "System", "subCategory": "System", "isEqual": true, "isPrasentinXml1": true, "isPrasentinXml2": true, "isPrasentinXml3": false, "atsortingbute": [ { "name": "numberofcpu", "firstValue": " 2\u000a", "secondValue": " 2\u000a" } ] }, { "id": "13", "elementName": "osname", "category": "System", "subCategory": "System", "isEqual": true, "isPrasentinXml1": true, "isPrasentinXml2": true, "isPrasentinXml3": false, "atsortingbute": [ { "name": "osname", "firstValue": "AIX\u000a", "secondValue": "AIX\u000a" } ] }, { "id": "14", "elementName": "release", "category": "System", "subCategory": "System", "isEqual": true, "isPrasentinXml1": true, "isPrasentinXml2": true, "isPrasentinXml3": false, "atsortingbute": [ { "name": "release", "firstValue": "1\u000a", "secondValue": "1\u000a" } ] }, { "id": "15", "elementName": "rulebaseserver", "category": "Product", "subCategory": "IIRServers", "isEqual": true, "isPrasentinXml1": true, "isPrasentinXml2": true, "isPrasentinXml3": false, "atsortingbute": [ { "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, "atsortingbute": [ { "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, "atsortingbute": [ { "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, "atsortingbute": [ { "name": "version", "firstValue": "6\u000a", "secondValue": "6\u000a" } ] }, { "id": "19", "elementName": "xmlconsoleserver", "category": "Product", "subCategory": "IIRServers", "isEqual": true, "isPrasentinXml1": true, "isPrasentinXml2": true, "isPrasentinXml3": false, "atsortingbute": [ { "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, "atsortingbute": [ { "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, "atsortingbute": [ { "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" } 

Si je comprends bien, vous devriez simplement utiliser l’option searchOnEnter: false de la barre d’outils de recherche. Certaines autres options pourraient également être utiles. J’utilise typiquement

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

et ajoutez en plus l’option ignoreCase: true à la grid. En passant, vous pouvez combiner la barre d’outils de recherche avec une boîte de dialog de recherche avancée qui permet de construire des requêtes plus complexes (voir la réponse ).