如何操纵jqGrid的搜索/过滤器?

Aar*_*ieb 6 javascript jquery jqgrid

我对此有一个导航栏一jqGrid的search: truemultipleSearch: true.我想在我的UI中添加一个按钮,自动为搜索添加一个额外的规则.

我已经尝试直接操作过滤器的postData,但是这样添加的值不会显示在搜索UI中.

我也尝试使用jQuery直接访问搜索框,如下所示:

$('#fbox_list').searchFilter().add();
$('#fbox_list .sf .data input').each(function(index) {
    alert($(this).val());
});
Run Code Online (Sandbox Code Playgroud)

但是,除了感觉hackish之外,它只有在用户已经点击了搜索按钮(fbox_list div不是在加载时构建)时才有效.

还有其他人处理过这样的问题吗?

Aar*_*ieb 7

为了后代,这是我目前正在使用的黑客.网格的ID为list,寻呼机的ID为pager:

jQuery(document).ready(function() {
    //Initialize grid.

    //Initialize the navigation bar (#pager)

    //Hack to force creation of the search grid.
    //The filter's ID is of the form #fbox_<gridId>
    jQuery('#pager .ui-icon-search').click();
    jQuery('#fbox_list').searchFilter().close();

    //Example button events for adding/clearing the filter.
    jQuery("#btnAddFilter").click(function() {
        //Adds a filter for the first column being equal to 'filterValue'.
        var postFilters = jQuery("#list").jqGrid('getGridParam', 'postData').filters;
        if (postFilters) {
            $('#fbox_list').searchFilter().add();
        }

        var colModel = jQuery("#list").jqGrid('getGridParam', 'colModel');
        //The index into the colModel array for the column we wish to filter.
        var colNum = 0;
        var col = colModel[colNum];

        $('#fbox_list .sf .fields select').last().val(col.index).change();
        $('#fbox_list .sf .data input').last().val('filterValue');

        $('#fbox_list .sf .ops select.field' + colNum).last().val('eq').change();

        $('#fbox_list').searchFilter().search();
    });

    jQuery("#btnClearFilter").click(function() {
        $('#fbox_list').searchFilter().reset();
    });
});
Run Code Online (Sandbox Code Playgroud)