Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I disable a filter conditionally in angularJS?

Tags:

angularjs

I am applying filter based on whether a record is active or not. There are basically three things 1)show all record 2)show active ones 3)show only those which are inactive

I can easily apply filtering for active or inactive using 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 on selecting Active Payhead/Inactive Payhead ,it filters out record with search.ph_active=0 or 1. But I need to show all records on selection of All Payhead. What is the way here?

like image 269
Rishi Avatar asked Nov 22 '25 19:11

Rishi


1 Answers

If you use an empty string it's like you don't specify filter criteria at all so all elements are shown, my first thought was to use null but it looks like null would be an actual value to compare while empty string match all elements

{name:"All Payhead",value:''}
like image 93
maurycy Avatar answered Nov 25 '25 11:11

maurycy