当我在网格中声明 searchOnEnter: true 时,它允许我在网格上进行搜索时使用 Enter 键。然而,当我按回车键进行搜索时,它根本不会过滤网格。然而,当我重复相同的操作两次时,过滤器会第二次起作用。我不知道为什么会发生这种情况。一个想法是,即使我清楚地输入了搜索文本,它可能第一次会发送一个空字符串,但我再次不确定。如有任何帮助,我们将不胜感激。
-亚当
最佳答案
要解决该问题,您需要修补 jqGrid 的源代码。您需要找到 keydown 事件的处理程序(当您在搜索对话框中按 Enter 按钮时运行的函数)。可以通过在源文件中搜索“searchOnEnter”找到此代码。正确的片段看起来是这样的:
if (p.searchOnEnter || p.closeOnEscape) {
$("#"+$.jgrid.jqID(IDs.themodal)).keydown(function (e) {
var $target = $(e.target);
if (p.searchOnEnter && e.which === 13 && // 13 === $.ui.keyCode.ENTER
!$target.hasClass('add-group') && !$target.hasClass('add-rule') &&
!$target.hasClass('delete-group') && !$target.hasClass('delete-rule') &&
(!$target.hasClass("fm-button") || !$target.is("[id$=_query]"))) {
这里您应该拆分代码行$("#"+fid+"_search").focus().click();
关于以下两项:
$("#"+fid+"_search").focus();
setTimeout(function(){
$("#"+fid+"_search").click();
},0);
以原始代码结尾:
return false;
}
(另请参阅 here )
关于javascript - JQGrid(搜索输入: true) Bug,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18857170/