Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi -

I'm trying to have a button click to reset the angularjs filters but nothing I have tried seems to work. When the button is clicked it should reset what ever filter options have already been chosen. The code I have produces an error of filter undefined.

Here is the code
Filters :
HTML
<div class="col-md-2">
    <select class="form-control" ng-model="typeFilter">
        <option value="">All</option>
        <option>Stock</option>
        <option>Special Order</option>
        <option>Part</option>
    </select>
</div>
<div class="col-md-2">
    <select class="form-control" ng-model="itemStatus">
        <option value="">All</option>
        <option>Active</option>
        <option>Discontinued</option>
        <option>Obsolete</option>
        <option>Deleted</option>
    </select>
</div>
<div class="col-md-2">
    <button type="button" class="btn btn-large button-dropdown" data-translate="Rest_Filters" ng-click="vm.clearFilter()"> Rest Filters</button>
</div>

Table data
HTML
      <tbody>
       <tr ng-repeat="item in vm.items | filter : {type : typeFilter || All} | filter:{status : itemStatus || All }">
             <td ng-bind="item.itemNo"> </td>
             <td ng-bind="item.description"></td>
             <td ng-bind="(item.listPrice | currency)"></td>
       </tr>
</tbody>


angularjs
JavaScript
vm.clearFilter = function ($scope) {

    $scope.typeFilter = "";
}


What I have tried:

I've tried

vm.clearFilter = function ($scope) {
$scope.typeFilter = "";
}
vm.clearFilter = function ($scope) {
$scope.typeFilter = {};
}
vm.clearFilter = function ($scope) {
$scope.type = {};
}
ng-click="typeFilter = {}"
Posted
Updated 28-Sep-17 6:06am

1 solution

In my HTML page I have this:

HTML
<div class="row">
                        <div class="col col-10">
                            <a class="button button-icon icon ion-search"></a>
                        </div>
                        <div class="col col-80">
                            <input type="text" placeholder="Busqueda de clientes..." class="largo100" ng-model="searchCli.Denominacion" >
                        </div>
                        <div class="col col-10">
                            <button ng-if="searchCli.Denominacion.length" class="button button-icon ion-android-close input-button" ng-click="clearSearch()">
                            </button>
                        </div>
                    </div>
                    <ion-scroll style="height=450px" delegate-handle="mainScroll">
                        <div class="list scroll-container">
                            <a class="item item-thumbnail-left item-button-right" ng-repeat="cliente in clientes | orderBy:'Denominacion' | filter:searchCli" ng-click="selectClient(cliente.IdCliente, cliente.Denominacion)" >
                                <img ng-src="img/locales/local1.jpg">
                                <h2>{{cliente.Denominacion}}</h2>
                                <p>{{cliente.Calle}}, {{cliente.Localidad}}</p>
                                <button class="button button-dark">
                                    
                                </button>
                            </a>
                        </div>
                    </ion-scroll>


And in my controller I have this:

JavaScript
$scope.searchCli = {};

$scope.clearSearch = function() {
   $scope.searchCli = {};
};


Works for me.

I hope it helps you. Regards
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900