Jqgrid on boot

I use the client side jqgrid filter function:

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 create my custom filters, for example, based on some flags:

 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 can’t apply a filter that matches the default selection at the end of the download or the completion of the grid:

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

If I delay execution a bit, everything works as expected:

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

How can I achieve this without using setTimeout?

+6
source share
1 answer

You can try using the Grid Complete method as follows.

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

0
source

All Articles