2012-10-30 43 views
6

我使用的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?

回答

0

可以請您嘗試使用Grid Complete方法,如下所述。

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