jqGrid:单字段搜索中的搜索规则

编程入门 行业动态 更新时间:2024-10-26 09:30:40
本文介绍了jqGrid:单字段搜索中的搜索规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试仅对整数数据的搜索字段进行验证,但不幸的是无法这样做.我已经尝试了所有可能的解决方案,例如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; }

jquery.jqGrid.src.js的固定版本可以获取此处.稍后,我将在我的错误报告中发布具有相同建议的错误报告.

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:单字段搜索中的搜索规则

本文发布于:2023-10-19 19:23:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1508524.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   规则   jqGrid

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!