Currently I have a grid set up with the search enabled. When I run a search everything works fine and I can return good data back to the grid. I see that the \"_search\" par
If you use jqGrid searching the following two things will be set
search
parameter of jqGrid will be set to true
.postData
parameter of jqGrid will be modified. The value of the postData
parameter is a object which has some properties. In case of single searching the properties searchField
, searchString
and searchOper
will be set. In case of advanced searching only the property filters
of the postData
parameter will be set. (The property _search
will be also set but from another component of jqGrid, so it is not important for the reset of searching.)So to reset the searching you can define the following event handler for your "Reset Search" button:
$("#resetSearch").click(function() {
var grid = $("#list");
grid.jqGrid('setGridParam',{search:false});
var postData = grid.jqGrid('getGridParam','postData');
$.extend(postData,{filters:""});
// for singe search you should replace the line with
// $.extend(postData,{searchField:"",searchString:"",searchOper:""});
grid.trigger("reloadGrid",[{page:1}]);
});
You can see all this live in the following demo. In the demo you should first click on the "Search" button of the navigation bar and set a search filter. Then you can click on the "Reset Search" button and reset it.
To clean the filter windows (both text and select) Had a following addition (whole function):
function filtReset() {
$("#list").jqGrid('setGridParam',{search:false});
var postData = $("#list").jqGrid('getGridParam','postData');
$.extend(postData, { filters: "" });
for (k in postData) {
if (k == "_search")
postData._search = false;
else if ($.inArray(k, ["nd", "sidx", "rows", "sord", "page", "filters"]) < 0) {
try {
delete postData[k];
} catch (e) { }
$("#gs_" + $.jgrid.jqID(k), $("#list").get(0).grid.hDiv).val("");
}
}
$("#list").trigger("reloadGrid", [{ page: 1}]);
// for singe search you should replace the line with
// $.extend(postData,{searchField:"",searchString:"",searchOper:""});
}