Can I disable a filter conditionally in angularJS?

I use a filter based on whether the entry is active or not. There are three things 1) show the entire entry 2) show active 3) show only those that are inactive

I can easily apply filtering for active or inactive using the following code

<div  ng-repeat="payhead in payHeadsList | filter:search">


<div style="float:left;width:65%" class="">
                <span style="float:left;" class="BodyTxt3 ML1">Show</span> 
                <select
                class="W2_Normal BodyTxt3 V4 ML1" style='float:left' id="selectPayHead"
                ng-model="search.ph_active"
                ng-options="a.value as a.name for a in payHeadOption"></select>
                </span>
 </div>


$scope.payHeadOption=[{name:"All Payhead",value:3},{name:"Active Payhead",value:1},{name:"Inactive Payhead",value:0}];

      

so when selecting Active Payhead / Inactive Payhead it filters the entry with search.ph_active = 0 or 1. But I need to show all entries about All Payhead selection. What's the way here?

+3


source to share


1 answer


If you are using an empty string, then as you do not specify the filter criteria so that all items are displayed, my first thought was to use it null

, but it looks like it null

would be the actual value to compare while the empty string matches all items



{name:"All Payhead",value:''}

      

+2


source







All Articles