1

我正在尝试仅验证整数数据的搜索字段,但不幸的是我无法这样做。我已经尝试了所有可能的解决方案,例如 searchrules:{required:true,integer=true} 等。但没有一个证明是富有成效的。我基本上使用该字段启动搜索对话框并且没有输入任何数据,我点击了“查找”按钮。根据上述选项,我相信应该向用户显示一条验证消息,要求他在点击查找之前在字段中输入一个值。

[更新] - 代码片段

            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"},
      {});

[更新]:无法使搜索规则在单一/高级搜索模式下正常工作。

[更新]:即使 jqGrid Demo中的“搜索验证”也不适用于搜索规则。

4

1 回答 1

0

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.

于 2013-04-19T17:57:07.673 回答