Skip to content Skip to sidebar Skip to footer

Angularjs Filter With An "OR" Operation On Data When We Have Multiple Filters

I checked other question but they don't seem to solve my issue. Here is my code : I have created custom functions $scope.filter111 and $scope.filter456 respectively to filter d

Solution 1:

You can try creating a custom angularJS filter by referring w3schools.com example and this link (for better understanding of custom filters).

In your case, the custom angularjs filter would take 3 inputs, i.e the list you want to filter and the value of the checkboxes- queue111 and queue456. Perform filtering and returning the data by providing necessary conditions based on the value of checkboxes inside the filter.

This also reduces the code that you use in your HTML for filtering inside ng-repeat from

<div ng-repeat="user in users|filter: queue111? filter111: ''|filter: queue456? filter456: ''">
    <p> {{user.name}} {{user.phone}}</p>
  </div>

to

<div ng-repeat="user in users|customFilter: queue111:queue456">
    <p> {{user.name}} {{user.phone}}</p>
  </div>

where

  1. customFilter is the name (can be any name, provided that name as an example) of the angularJS filter you create.
  2. users will be the default first input of your custom filter and the value of your checkboxes will be the 2nd and 3rd input respectively.

Also, it would be helpful if you provide codepen/plunker demos so that people can debug your problem and provide solutions easily.


Post a Comment for "Angularjs Filter With An "OR" Operation On Data When We Have Multiple Filters"