jqGrid : searchrules in single Field searching

廉价感情. 提交于 2020-01-14 02:59:30

问题


I'm trying to validate the search field for integer data alone but unfortunately am unable to do so. I have tried all possible solutions like searchrules:{required:true,integer=true} etc.. But none of them proves fruitful. I basically launch the search dialog with the field and without inputting any data, am hitting on the 'Find' button. As per the above options, i believe a validation message should be shown to the user asking him to enter a value in the field before hitting find.

[UPDATED] - Code Snippet

            var grid = $("#list");  
            grid.jqGrid({
             url:'/index.jsp',
             datatype: 'json',
             mtype: 'POST',
             colNames:['Name','Age', 'Address'],
             colModel :[ 
                  {name:'name', index:'name', width:55,search:true }, 
                  {name:'age', index:'age', 
                   width:90,editable:true,search:true, stype:'text',
                   searchrules:{required:true,integer:true}}, 
                  {name:'address', index:'address', width:80, 
                   align:'right', editable: true,search:false }
             ],
             pager: '#pager',
             jsonReader : {
                     root:"address",
                     page: "page",
                     total: "total",
                     records: "records",
                     repeatitems: false
             },
             rowNum:10,
             rowList:[10,20,30],
             sortname: 'name',
             sortorder: 'desc',
             viewrecords: true,
             gridview: true,
             autowidth: true,
             toppager: true,
             loadtext: "Loading records.....",
             caption: 'Test Grid',
             gridComplete: function(){ 

         }

          });

      **grid**.jqGrid('navGrid','#pager',
      {view:true,edit:true,add:true,del:true,refresh:true,
       refreshtext:'Refresh',addtext:'Add',
       edittext:'Edit',cloneToTop:true,
       edittitle: "Edit selected row"},
      {},{},{},
      {caption: "Search The Grid",Find: "Find Value",Reset: "Reset"},
      {});

[Updated] : Am not able to make the searchrules properly work for the single/advanced searching modes.

[Updated] : Even the 'Validation in Search' in jqGrid Demo is not working for searchrules.


回答1:


The reason of described problem is a bug in jqGrid. The line

ret = $.jgrid.checkValues(val, -1, null, colModelItem.searchrules, colModelItem.label);

initialize the third parameter of $.jgrid.checkValues to null, but the last version of checkValues implementation started (see the line) with

var cm = g.p.colModel;

but g is initialized to null. The last modification which generates the error was based on my suggestion, but I don't wrote the part of the code.

One can solve the problem in different way. I would suggest to modify the line where $.jgrid.checkValues will be called with null parameter to the following

ret = $.jgrid.checkValues(val, -1, {p: {colModel: p.columns}}, colModelItem.searchrules, colModelItem.label);

Additionally, to be sure, I would suggest to modify one more line

if(!nm) { nm = g.p.colNames[valref]; }

to

if(!nm) { nm = g.p.colNames != null ? g.p.colNames[valref] : cm.label; }

The fixed version of jquery.jqGrid.src.js one can get here. I will post my bug report with the same suggestions later ti trirand.



来源:https://stackoverflow.com/questions/16050565/jqgrid-searchrules-in-single-field-searching

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!