代码之家  ›  专栏  ›  技术社区  ›  AaronSieb

如何操作jqgrid的搜索/过滤器?

  •  6
  • AaronSieb  · 技术社区  · 16 年前

    我有一个带导航条的jqgrid search: true multipleSearch: true . 我想添加一个按钮到我的用户界面,自动添加一个额外的规则到搜索。

    我尝试直接操作过滤器的postdata,但是以这种方式添加的值不会显示在搜索用户界面中。

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

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

    但是,除了感觉黑客,只有当用户已经点击了搜索按钮(fbox_list div不是在加载时构建的)时,它才起作用。

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

    3 回复  |  直到 12 年前
        1
  •  7
  •   AaronSieb    16 年前

    为了子孙后代,这是我目前使用的黑客。网格的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();
        });
    });
    
        2
  •  0
  •   dlewicki    15 年前

    如果您的意思是过滤器工具栏,您可以这样做:(状态是列名称——所以,替换“GS U status”w/“GS UUU”+您的U col U名称

            jQuery("#distributor_grid").jqGrid('showCol',['status']);           
            jQuery(".ui-search-toolbar #gs_status")
                .val('ALL')
                ;
    
            $('#distributor_grid').RefreshData();  // triggers toolbar
    

        3
  •  0
  •   Harry dbr    12 年前

    要清除输入,请选择并重置网格

    $("td#refresh_navGrid").click();
    
    推荐文章