low_rents low_rents - 1 year ago 155
Javascript Question

how to reset the search toolbar and search filters in newer versions of free-jqgrid?

for older versions of

i used a function to reset the search toolbar and filters:

function resetSearchToolbar()
var col_arr = $("#grid").jqGrid("getGridParam", "colModel");
var toolbar_selector;

for(var i = 0, max = col_arr.length; i < max; i++)
if(col_arr[i].search && $("#gs_" + col_arr[i].name).val().length)
toolbar_selector = $("#gs_" + col_arr[i].name)

// trigger toolbar searching with key-event:
if(typeof toolbar_selector !== "undefined")

this was kind of a very bad hack - but it worked for me.

is there a better way to achieve this in newer versions of free-jqgrid (4.13+)?

Answer Source

Free jqGrid 4.13.0 implemented new feature: filling the filter toolbar based on the current searching filter postData.filters in case of the filter is really applied (search:true option is set in jqGrid). If you don't want to have the feature one can use loadFilterDefaults: true option of filterToolbar.

The feature had some small bugs in some test case, but the version 4.13.2 should have all the problem fixed.

Free jqGrid support jqGridRefreshFilterValues event, which can be triggered to force reloading of the filters (without reloading of the grid). On reloading of the grid the filters will be reloaded of cause.

Thus if you changed postData.filters or search options and you want that the changes will be applied immediately then you need just trigger the jqGridRefreshFilterValues event:


If you set for example search: false before triggering the event then all fields of the filter toolbar will be cleared:

var $grid = $("#grid");
$grid.jqGrid("getGridParam").search = false;

If you would like to clear the filter and to reload the grid then you can use old jqGrid method clearToolbar instead (see the old documentation):