Author Topic: Clear filters v3.2.0  (Read 3011 times)

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Clear filters v3.2.0
« on: June 08, 2016, 02:00:23 pm »
Hi

Trying to creatte button to clear filters with code:

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

          var CM = $grid.pqGrid.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.pqGrid.refreshHeader();
            $grid.pqGrid.filter({
                oper: 'replace',
                data: []
            });

       }
 }
]
}

but get error: Uncaught TypeError: $grid.pqGrid.getColModel is not a function...

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Clear filters v3.2.0
« Reply #1 on: June 08, 2016, 05:50:11 pm »
That's incorrect syntax to call methods.

Instead of $grid.pqGrid.getColModel(), please try this: $grid.pqGrid( "getColModel" );

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Re: Clear filters v3.2.0
« Reply #2 on: June 08, 2016, 06:14:48 pm »
Thanks. Modified code:

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

          var CM = $grid.pqGrid( "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.pqGrid( "refreshHeader" );
            $grid.pqGrid( "filter" );({
                oper: 'replace',
                data: []
            });

       }
 }
]
}

now gives: "Uncaught TypeError: Cannot read property 'apply' of undefined"...

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Clear filters v3.2.0
« Reply #3 on: June 08, 2016, 09:14:18 pm »
Filter method call is incorrect.

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

Please correct it:
Code: [Select]
$grid.pqGrid( "filter", {
                oper: 'replace',
                data: []
            });