views:

77

answers:

2

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..

??

A: 

To click the "reset" button try:

$(".ui-reset").click();
Mark
Will try that - my post might be slightly misleading.. What I'm trying to do is clear the search options and call `trigger("reloadGrid")`. Your suggestion might work.. though would prefer to not literally call `click`.. would like to call a `clearSearchOptions()` method then call `trigger("reloadGrid")`
Marcus
A: 

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.

Oleg
Thanks Oleg - but this doesn't appear to reset the grid's search UI. That is the prior search criteria still show up when you click the search button in the nav bar. I'd like to clear these out.
Marcus
@Marcus: You asked how to reset jqGrid search options. So I understood that you opened Search dialog set options and then close the search dialog. The search options stay saved in the jqGrid. So I answered how th reset the options. What you then mean? By the way do you use `recreateFilter:true` option?
Oleg
We don't use the `recreateFilter` option.. if we manually set postdata, the search data stays saved in the grid - how do you remove the search from the grid so the gui doesn't show any search options selected?
Marcus
@Marcus: Could you explain what scenario you mean? Why do you decide that "the search data stays saved in the grid"? What do you mean? How one can reproduce your problem and which behavior exactly you want to have in jqGrid? In general there are search filter in the grid (as a part of postData) and there are a search dialog which will be hide or show. If you use `recreateFilter:true` option the dialog will be always new created instead of showing previously created hide dialog.
Oleg
We have our search icon on the nav. Users can click this button, search on multiple fields - all this works great. We have another filter option outside of the grid control. If users select another type of filter, we change the grid url and call reloadGrid. But when we call reloadGrid the filter options that the user selected with the grid search are still present. What is the best way to clear out the grid search criteria?
Marcus
@Marcus: It is exactly the scenario which I mean as I wrote my answer. If the code from my answer not work then try `var sdata={searchField:"",searchOper:"",searchString:""}; $.extend($("#list")[0].p.postData,sdata); $("#list")[0].p.search=false;`
Oleg
Tried both - couldn't get either to work - search GUI still has prior selections in place. As I'm using the advanced search I modified your last example slightly to use `var sdata={filters:""};`
Marcus
@Marcus: I can repeat only once. You should post a full code example then I'll try to modify it so that it will work.
Oleg