low_rents
low_rents

Reputation: 4481

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

for older versions of free-jqgrid 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)
            toolbar_selector.val("");
        }
    }

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

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+)?

Upvotes: 1

Views: 3011

Answers (2)

Oleg
Oleg

Reputation: 221997

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:

$("#grid").triggerHandler("jqGridRefreshFilterValues");

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;
$grid.triggerHandler("jqGridRefreshFilterValues");

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):

$("#grid")[0].clearToolbar();

Upvotes: 3

low_rents
low_rents

Reputation: 4481

I just found out that:

$("#grid").setGridParam({ postData: { filters: {}} }).trigger("reloadGrid");

seems to work out perfectly.

Upvotes: 1

Related Questions