Using jqGrid multiple searching how can you programatically "clear" the search options?
The "clear" should ensure no filters
are being sent to the server and that the GUI search box does not contain any search criteria..
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..
??
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.
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:
_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 Searching instead of Single Searching you should clear filters
property instead of searchField
, searchOper
and searchString
.
At the end you can call $("#list").trigger("reloadGrid",[{page:1}]);
to reload the grid contain starting with the page number 1.
To click the "reset" button try:
$(".ui-reset").click();
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With