如何在free-jqgrid的较新版本中重置搜索工具栏和搜索过滤器? [英] how to reset the search toolbar and search filters in newer versions of free-jqgrid?

查看:79
本文介绍了如何在free-jqgrid的较新版本中重置搜索工具栏和搜索过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于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");
}

这是一个非常糟糕的hack-但这对我有用.

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

在新版本的free-jqgrid(4.13+)中是否有更好的方法来实现此目的?

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

推荐答案

免费的jqGrid 4.13.0实现的新功能:如果确实应用了过滤器,则基于当前搜索过滤器postData.filters填充过滤器工具栏(选项在jqGrid中设置).如果您不想使用此功能,可以使用filterToolbarloadFilterDefaults: true选项.

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.

该功能在某些测试用例中有一些小错误,但是4.13.2版应该解决了所有问题.

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

免费的jqGrid支持jqGridRefreshFilterValues事件,可以触发该事件以强制重新加载过滤器(不重新加载网格).重新加载网格后,过滤器将重新加载.

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.

因此,如果您更改了postData.filterssearch选项,并且希望立即应用更改,则只需触发jqGridRefreshFilterValues事件:

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");

如果在触发事件之前设置例如search: false,则将清除过滤器工具栏的所有字段:

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");

如果您想清除过滤器并重新加载网格,则可以改用旧的jqGrid方法clearToolbar(请参见

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();

这篇关于如何在free-jqgrid的较新版本中重置搜索工具栏和搜索过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆