Pre-select filters in jqgrid (multi-select)
Asked Answered
P

1

1

Taking this example (http://www.ok-soft-gmbh.com/jqGrid/SimpleLocalGridWithSearchingToolbarMultilpe.htm) from this question (Excel like filtering in jqgrid)

Is there a way to set the filter parameters from the start? For example, in the 'Shipped via' column, I would want 'TNT' and 'Intim' to be checked, leaving 'FedEx' unchecked.

One solution I thought was viable is to ship_via

if(id == 'gs_ship_via'){ 
                        _.forEach($options, function(option){
                            if(option.value != 'FexEx'){
                                option.selected = true; 
                            } else {
                                option.selected = false;    
                            }
                        });
                    }

The problem I run into after that is that it doesn't update the data in the grid. So, I need a different way to set the check box after it's loaded in a way that will update the grid.

Puleo answered 30/3, 2015 at 13:36 Comment(0)
E
1

I suppose that you need to include trigger of change event ($("#gs_ship_via").change();) or to call triggerToolbar ($grid[0].triggerToolbar();). The exact solution can heavy depend on the place where you made the changes. If you would make the changes of multi-select options for example after initializing of multiselect you could see wrong multiselect options and you could require to call refresh.

See the demo which displays the results like

enter image description here

Probably one can modify the solution for setting multiple values which uses the idea from the answer, but it will take a little more time as I have currently. :-(

Exterritorial answered 30/3, 2015 at 16:21 Comment(1)
The .change and .triggerToolbar seem to do the trick. Thanks!Puleo

© 2022 - 2024 — McMap. All rights reserved.