jqgrid on load完成应用过滤器

时间:2012-10-30 10:34:58

标签: jquery jqgrid

我正在使用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的情况下实现此目的?

1 个答案:

答案 0 :(得分:0)

你可以尝试使用Grid Complete方法,如下所述。

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