jqGrid:单字段搜索中的搜索规则 [英] jqGrid : searchrules in single Field searching
问题描述
我正在尝试仅对整数数据的搜索字段进行验证,但不幸的是无法这样做.我已经尝试了所有可能的解决方案,例如searchrules:{required:true,integer = true}等. 但没有一个能证明富有成效. 我基本上是使用该字段启动搜索对话框的,并且没有输入任何数据,而是点击了查找"按钮.根据上述选项,我认为应该向用户显示一条验证消息,要求他在单击查找之前在字段中输入一个值.
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.
[已更新]-代码段
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.
[更新]:即使是搜索中的验证" jqGrid演示不适用于搜索规则.
[Updated] : Even the 'Validation in Search' in jqGrid Demo is not working for searchrules.
推荐答案
所描述问题的原因是jqGrid中的错误. 该行
The reason of described problem is a bug in jqGrid. The line
ret = $.jgrid.checkValues(val, -1, null, colModelItem.searchrules, colModelItem.label);
将$.jgrid.checkValues
的第三个参数初始化为null
,但是checkValues
实现的最后一个版本开始了(请参阅
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;
,但g
初始化为null
. 产生错误的最后修改基于
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.
一个人可以用不同的方式解决问题.我建议将使用null
参数调用$.jgrid.checkValues
的行修改为以下
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]; }
到
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.
这篇关于jqGrid:单字段搜索中的搜索规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!