简体   繁体   English

如何在较新版本的free-jqgrid中重置搜索工具栏和搜索过滤器?

[英]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: 对于旧版本的free-jqgrid我使用了一个功能来重置搜索工具栏和过滤器:

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+)? 在较新版本的free-jqgrid(4.13+)中是否有更好的方法来实现此目的?

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). 免费的jqGrid 4.13.0实现的新功能:如果确实应用了过滤器,则基于当前搜索过滤器postData.filters填充过滤器工具栏(在jqGrid中设置了search:true选项)。 If you don't want to have the feature one can use loadFilterDefaults: true option of filterToolbar . 如果你不希望有功能可以使用loadFilterDefaults: true的选项filterToolbar

The feature had some small bugs in some test case, but the version 4.13.2 should have all the problem fixed. 该功能在某些测试用例中有一些小错误,但是版本4.13.2应该可以解决所有问题。

Free jqGrid support jqGridRefreshFilterValues event, which can be triggered to force reloading of the filters (without reloading of the grid). 免费的jqGrid支持jqGridRefreshFilterValues事件,可以触发该事件以强制重新加载过滤器(而无需重新加载网格)。 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: 因此,如果您更改了postData.filterssearch选项,并且希望更改将立即应用,则只需触发jqGridRefreshFilterValues事件:

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

If you set for example search: false before triggering the event then all fields of the filter toolbar will be cleared: 如果您在触发事件之前将示例设置为search: false ,则将清除过滤器工具栏的所有字段:

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 ): 如果您想清除过滤器并重新加载网格,则可以改用旧的jqGrid方法clearToolbar (请参见旧文档 ):

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

I just found out that: 我刚发现:

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

seems to work out perfectly. 看起来很完美。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM