ParamQuery grid support forum

General Category => Help for ParamQuery Pro => Topic started by: queensgambit9 on January 16, 2023, 12:46:24 am

Title: Filter question
Post by: queensgambit9 on January 16, 2023, 12:46:24 am
Hi

I would like to clear filter (if exists) on a column when it changes from visible to hidden.
I used this before: https://paramquery.com/forum/index.php?topic=2355

Now using 8.7.0 with updated show / hide functionality how could it be implemented?
Title: Re: Filter question
Post by: paramvir on January 16, 2023, 01:04:43 pm
hideCols event can be used for this.

Code: [Select]
hideCols: function(evt, ui){
var grid = this;
ui.diHide.forEach(function(di){
var col = grid.getColumn({dataIndx: di});
if(col.filter && col.filter.crules){
col.filter.crules.forEach(function(rule){
rule.value = undefined; //clear the values while keep the filter conditions.
rule.value2 = undefined;
});
}
});
grid.filter();//refresh filter.
},
Title: Re: Filter question
Post by: queensgambit9 on January 18, 2023, 08:22:36 pm
Thanks, works fine.
Title: Re: Filter question
Post by: queensgambit9 on January 19, 2023, 07:04:47 pm
By the way I would like to clear/refresh filter only if filter was set to avoid unnecessary call to db...what would be a good way to do this?
Title: Re: Filter question
Post by: queensgambit9 on January 19, 2023, 07:20:21 pm
did like this:

Code: [Select]
if (rule.value != undefined || rule.value2 != undefined) {
  rule.value = undefined; //clear the values while keep the filter conditions.
  rule.value2 = undefined;
  grid.filter();//refresh filter.
  }

or is there a better way?
Title: Re: Filter question
Post by: paramvir on January 20, 2023, 03:35:46 pm
Code: [Select]
hideCols: function(evt, ui){
var grid = this, requireRefresh;
ui.diHide.forEach(function(di){
var col = grid.getColumn({dataIndx: di});
if(col.filter && col.filter.crules){
col.filter.crules.forEach(function(rule){
                                                    if (rule.value != undefined || rule.value2 != undefined) {
                                                        requireRefresh = true;
rule.value = rule.value2 = undefined; //clear the values while keep the filter conditions.
                                                    }
});
}
});

                               if( requireRefresh ) grid.filter();//refresh filter.
},