jQuery jqGrid - 如何重置搜索选项?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3865584/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jqGrid - how to reset search options?
提问by Marcus Leon
Using jqGrid multiple searchinghow can you programatically "clear" the search options?
使用 jqGrid 多重搜索如何以编程方式“清除”搜索选项?
The "clear" should ensure no filters
are being sent to the server and that the GUI search box does not contain any search criteria..
“清除”应确保没有filters
被发送到服务器,并且 GUI 搜索框不包含任何搜索条件。
We are currently calling trigger("reloadGrid")
. We'd like to call a clearSearchCrieria()
type method before reloadGrid so that no filters
are passed to the server or show up in the GUI search box..
我们目前正在调用trigger("reloadGrid")
. 我们想clearSearchCrieria()
在 reloadGrid 之前调用一个类型方法,以便没有filters
传递到服务器或显示在 GUI 搜索框中..
??
??
回答by Jimbo
You could use the following method:
您可以使用以下方法:
function clearSearchOptions(){
$("#list").jqGrid('setGridParam', { search: false, postData: { "filters": ""} }).trigger("reloadGrid");
}
But as Oleg pointed out, you will have to use the recreateFilter:true
option in your jqgrid definition if you want the jqgrid search box to be cleared as well.
但正如 Oleg 指出的那样,recreateFilter:true
如果您还希望清除 jqgrid 搜索框,则必须在 jqgrid 定义中使用该选项。
回答by Oleg
To reset filters you can modify the postData
parameter of jqGrid directly. You can access it with $("#list").jqGrid('getGridParam','postData')
or $("#list")[0].p.postData
. If a filter is set, the properties of the postData
look like following:
要重置过滤器,您可以postData
直接修改jqGrid的参数。您可以使用$("#list").jqGrid('getGridParam','postData')
或访问它$("#list")[0].p.postData
。如果设置了过滤器,则属性postData
如下所示:
_search true Boolean
nd 1286296925096 Number
page 1 Number
rows 10 Number
searchField "id" String
searchOper "lt" String
searchString "5" String
sidx "id" String
sord "desc" String
To reset the properties you can do following
要重置属性,您可以执行以下操作
var postdata = $("#list").jqGrid('getGridParam','postData');
postdata._search = false;
postdata.searchField = "";
postdata.searchOper = "";
postdata.searchString = "";
If you use Advanced Searchinginstead of Single Searchingyou should clear filters
property instead of searchField
, searchOper
and searchString
.
如果您使用高级搜索而不是单一搜索,您应该清除filters
属性而不是searchField
,searchOper
和searchString
。
At the end you can call $("#list").trigger("reloadGrid",[{page:1}]);
to reload the grid contain starting with the page number 1.
最后,您可以调用$("#list").trigger("reloadGrid",[{page:1}]);
以重新加载从页码 1 开始的网格包含。
回答by Mark
To click the "reset" button try:
要单击“重置”按钮,请尝试:
$(".ui-reset").click();
回答by neeraj
It will reset all search options
它将重置所有搜索选项
$('input[id*="gs_"]').val("");
回答by Peter Munnings
The only way I could get it right - and I'm sure its not the right way is as follows:
我能做到的唯一方法 - 我确定它不是正确的方法如下:
$("#grid").jqGrid('setGridParam', { postData: { filters: null} });
$("#gs_ColName1").val("");
$("#gs_ColName2").val("");
where ColNameX are the names of your columns
其中 ColNameX 是列的名称
回答by user2675617
$("#resetFilterOptions").click(function(){
$('input[id*="gs_"]').val("");
$('select[id*="gs_"]').val("ALL");
$("#list").jqGrid('setGridParam', { search: false, postData: { "filters": ""} }).trigger("reloadGrid");
});
This one works Rest Search options and Reload the JQGrid
这个可以使用 Rest Search 选项并重新加载 JQGrid
回答by Rakesh
$("#search").filterGrid("#list", {
gridModel: false,
enableSearch: true,
filterbutton: 'search_button',
enableClear:true,
filterModel: [{
label: 'First Name',
name: 'search',
stype: 'text'
});
Write enableClear:true
in your filterGrid
写enableClear:true
在你的filterGrid
回答by Mateus Padua
use only
只使用
$("td#refresh_navGrid").click();
$("td#refresh_navGrid").click();
回答by Khine Lae
I added external refresh button to solve this.
我添加了外部刷新按钮来解决这个问题。
jgrid.jsp
jgrid.jsp
<sj:submit id="grid_refreshbutton" value=" Refresh" button="true"/>
jgrid.js
jgrid.js
$(document).ready(function(){
jQuery("#grid_refreshbutton").click(function(){
var postData = $("#gridtable").jqGrid('getGridParam','postData');
$("#gridtable").jqGrid('setGridParam',{search:false});
$.extend(postData, { filters: "" });
for (k in postData) {
if (k == "_search")
{ postData._search = false;}
else if ($.inArray(k, ["nd", "sidx", "rows", "sord", "page", "filters"]) < 0) {
delete postData[k];
("#gs_" + $.jgrid.jqID(k), $("#gridtable").get(0).grid.hDiv).val("");
}
}
$("#gridtable").trigger("reloadGrid", [{ page: 1}]);
});
});
Thanks/Regards, Khine lae
谢谢/问候, Khine lae