Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jqGrid - how to reset search options?

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

??

like image 561
Marcus Leon Avatar asked Oct 05 '10 16:10

Marcus Leon


4 Answers

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.

like image 175
Jimbo Avatar answered Oct 19 '22 22:10

Jimbo


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.

like image 41
Oleg Avatar answered Oct 19 '22 22:10

Oleg


To click the "reset" button try:

$(".ui-reset").click();
like image 34
Mark Avatar answered Oct 19 '22 23:10

Mark


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

like image 38
Peter Munnings Avatar answered Oct 19 '22 22:10

Peter Munnings