jqgrid on load complete apply filter
Asked Answered
A

1

6

I am using jqgrid's client-side filter feature:

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(),
                                      } );

I am building my custom filters like this based on some checkboxes:

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);
}

My problem is that i cannot apply the filter that corresponds to the default selection at load complete time or at grid complete:

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

If i delay the execution a little everything works as expected:

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

How can i achieve this without using setTimeout?

Arsenical answered 30/10, 2012 at 10:34 Comment(0)
L
0

can you please try with Grid Complete method as mentioned below.

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

Laceration answered 12/1, 2015 at 6:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.