6

我正在使用 jqgrid 的客户端过滤器功能:

var opts = {  
            ...
            loadonce: true,
            ...
}

var grid = jQuery("#Grid");
grid.jqGrid(opts)
grid.jqGrid('navGrid','#mpager',{edit:false, 
                                     add:false,
                                     del:false}, {}, {}, {}, 
                                     {
                                      multipleSearch:true, 
                                      multipleGroup:true,
                                      recreateFilter: true,
                                      overlay: 0,
                                      tmplNames: ['Not Empty','All','=10kw','fg'],
                                      tmplFilters: populateStaticFilters(),
                                      } );

我正在基于一些复选框构建这样的自定义过滤器:

var filter = { "groupOp": "OR",
               "rules": []
}

var rules = {
    factive :  { "field": "Total", "op": "nn", "data": "" },
    fempty :  { "field": "Total", "op": "nu", "data": "" },
    f10 :  { "field": "Power", "op": "eq", "data": "10" },
    factivetoday  :   { "field": "LastUpdate", "op": "eq", "data": today },
}

function jqgselectFilter(myfilter){
    grid = jQuery("#Grid");
    //console.log(myfilter);
    grid[0].p.search = myfilter['rules'].length>0;
    jQuery.extend(grid[0].p.postData,{filters:JSON.stringify(myfilter)});
    grid.trigger("reloadGrid",[{page:1}]);    
}

function populateFilter() {
        filter['rules']=[]
        if (jQuery('input[name=showactive]').attr('checked')) {
            filter['rules'].push(rules['factive']);
        }
        if (jQuery('input[name=showempty]').attr('checked')) {
            filter['rules'].push(rules['fempty']);
        }
        if (jQuery('input[name=showactivetoday]').attr('checked')) {
            filter['rules'].push(rules['factivetoday']);
        }
        //console.log(filter);
        jqgselectFilter(filter);
}

我的问题是我无法在加载完成时或网格完成时应用与默认选择相对应的过滤器:

grid.jqGrid('setGridParam', { "loadComplete": populateFilter() });

如果我稍微延迟执行,一切都会按预期工作:

setTimeout('populateFilter();',500);

我如何在不使用 setTimeout 的情况下实现这一点?

4

1 回答 1

0

你能试试下面提到的网格完成方法吗?

grid.jqGrid('setGridParam', { "gridComplete": populateFilter() });

于 2015-01-12T06:52:46.817 回答