Author Topic: Clear Filters in Grid  (Read 5714 times)

gammax500

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 16
    • View Profile
Clear Filters in Grid
« on: October 01, 2015, 10:16:05 pm »
I searched in the forums for how to clear added grid filters and found only one old post about this http://paramquery.com/forum/index.php?topic=519.msg3184;topicseen#msg3184, where the solution was to add $grid.pqGrid( "filter", { oper:'replace', data: [] } ); to the click event for the toolbar button.

That works to clear the filters from the grid and restore the data, however it leaves the text typed into the filter text fields.  How do I clear out this text?

toolbar:

{ type: 'button', label: 'Clear Filters', listeners: [
     {
      "click": function (evt, ui) {

          $grid.pqGrid( "filter", { oper:'replace', data: [] } );

       }
 }
]
},

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6260
    • View Profile
Re: Clear Filters in Grid
« Reply #1 on: October 02, 2015, 01:40:14 pm »
Please use this code in the click event, where grid is the widget instance.
Code: [Select]
                        var CM = grid.getColModel();
                        for(var i=0, len = CM.length; i < len; i++){
                            var column = CM[i];
                            if(column.filter){
                                column.filter.value = null;
                                column.filter.cache = null;
                            }
                        }
                        grid.refreshHeader();
grid.filter({
oper: 'replace',
data: []
});
« Last Edit: October 02, 2015, 01:49:10 pm by paramquery »

gammax500

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Clear Filters in Grid
« Reply #2 on: October 06, 2015, 03:21:36 am »
Thanks,

I tried the code block and it reset almost every filter, however one of my filters is a date range.  Your code cleared the first but not the second of the dates.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6260
    • View Profile
Re: Clear Filters in Grid
« Reply #3 on: October 06, 2015, 08:04:32 am »
Please add column.filter.value2 = null; beside column.filter.value = null;