Author Topic: clear other select filters when active change listener fires  (Read 4199 times)

interloper10

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 14
    • View Profile
clear other select filters when active change listener fires
« on: January 07, 2016, 10:16:05 pm »
I have a (working) grid with multiple select type column filters. The filtermodel mode is AND.

Is it possible to override the active change listener to clear the filter values on the other (non-active) filters?

Here is a suggestion: have another filterModel mode of 'CLEAR' or 'RESET' (something like this) that would clear out the other filters prior to applying the active filter.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6313
    • View Profile
Re: clear other select filters when active change listener fires
« Reply #1 on: January 07, 2016, 11:46:52 pm »
That is possible by implementing a custom listener and calling filter method directly with 'oper' parameter as 'replace'

Example to implement a custom change listener: http://paramquery.com/pro/demos/filter_date

API for filter method: http://paramquery.com/pro/api#method-filter

interloper10

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: clear other select filters when active change listener fires
« Reply #2 on: January 08, 2016, 01:24:36 am »
In the API doc (V3), dataIndx should be data > condition

I following you, but struggling with the examples. 

I've tried to replace the filter and then call flex method.  I have array/TEXT data and columns defined like this:

            { title: "Group Type", dataType: "string", dataIndx: 0,
                filter: {
                    type: 'select',
                    condition: 'equal',
                    value: 'Total',
                    valueIndx: 0,
                    labelIndx: 0,
                    on: true,
                    prepend: { '': ' Select' },
                    listeners: ['change']
                }               
            },
            { title: "Group Value", dataType: "string", dataIndx: 1,
                filter: {
                    type: 'select',
                    condition: 'equal',
                    value: 'Total',
                    valueIndx: 1,
                    labelIndx: 1,
                    groupIndx: 0,
                    on: true,
                    prepend: { '': ' Select' },
                    listeners: [{ 'change': function (evt, ui) {
                        $( ".selector" ).pqGrid('filter', {
                            oper: 'replace', data: [{ dataIndx: 0, condition: 'equal', value: null }]
                        });
                        $( ".selector" ).pqGrid( "flex", {
                            dataIndx: [ 0, 1 ]
                        } );
                    }}]
                }
            }

Am I on the right path here? - appreciate the help.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6313
    • View Profile
Re: clear other select filters when active change listener fires
« Reply #3 on: January 08, 2016, 01:55:05 pm »
listener would be as below where grid is javascript widget instance of pqGrid.

Code: [Select]
listeners: [{ 'change': function (evt, ui) {

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;
                        }
                }
setTimeout(function(){
grid.refreshHeader();
},0);
                grid.filter({
                   oper: "replace",
                   data: [ui]
                })
        }
}]
« Last Edit: January 08, 2016, 01:58:24 pm by paramquery »

interloper10

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: clear other select filters when active change listener fires
« Reply #4 on: January 09, 2016, 04:00:13 am »
Perfect - thank you!  :)