我正在尝试使用数据库存储和加载搜索模板。这样做时,我无法更改tmplLabel,tmplNames,tmplFilters的值。 我正在调用loadTemplates()函数,该函数进入服务器以获取数据并存储在3个变量中。在loadComplete()中调用此函数。 请让我知道如何重置模板的值。 我说的是http://www.trirand.com/blog/jqgrid/jqgrid.html
之类的东西答案 0 :(得分:0)
搜索模板是一项有趣的功能,不常用。要使用它,应使用tmplNames
和tmplFilters
(可选tmplLabel
),它们是搜索模块的parameters。如果您另外使用recreateFilter: true
选项很重要。所以你可以设置
var mySearchOptions = {
// it's just some options which you use
multipleSearch: true,
multipleGroup: true,
recreateFilter: true,
closeOnEscape: true,
closeAfterSearch: true,
overlay: 0
},
$grid = $("#grid");
$grid.jqGrid({
// ... your jqGrid options
loadComplete: function (data) {
// you should modify the next line correspond to the place of
// tmplNames and tmplFilters in the server response
if (data.tmplNames && data.tmplFilters) {
mySearchOptions.tmplNames = data.tmplNames;
mySearchOptions.tmplFilters = data.tmplFilters;
}
}
});
$grid.jqGrid('navGrid', {/*navGrid option*/}, {/*Edit options*/}, {/*Add options*/},
{/*Del options*/},
mySearchOptions);
我认为您已经有了正确的代码,但是您没有使用recreateFilter: true
选项。因此,将显示先前打开的搜索对话框,而不是使用当前选项重新创建对话框。
P.S。我建议你另外刷新jqGrid 4.3.2的源代码(参见the answer)。您将获得更好的键盘支持,可以在搜索对话框中使用searchOnEnter
和closeOnEscape
选项,afterChange
回调和自定义控件(请参阅the answer)。