Author Topic: Filter question  (Read 572 times)

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Filter question
« 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?
« Last Edit: January 16, 2023, 02:06:40 am by queensgambit9 »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: Filter question
« Reply #1 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.
},

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: Filter question
« Reply #2 on: January 18, 2023, 08:22:36 pm »
Thanks, works fine.

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: Filter question
« Reply #3 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?
« Last Edit: January 19, 2023, 07:09:41 pm by queensgambit9 »

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: Filter question
« Reply #4 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?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: Filter question
« Reply #5 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.
},