1

I am trying to use or condition filter in ui select and I am not sure how to process that. I have a similar question answered here. But that is asked for using AND condition which works for me too. Here is my code

HTML

<ui-select ng-model="citySelected">
    <ui-select-match>
        {{$select.selected.name + ', ' + $select.selected.country}}
    </ui-select-match>
    <ui-select-choices repeat="city in List | filter: {name: $select.search} | orderBy:'sortOrder'">
        <span ng-bind-html="city.name + ', ' + city.country| highlight: $select.search"></span>
    </ui-select-choices>
</ui-select>

1 Answer 1

2

I am using a properties filter to search through any of the parameters that I have specified.

    app.filter('propsFilter', function() {
       return function(items, props) {
           var out = [];

           if (angular.isArray(items)) {
               items.forEach(function(item) {
               var itemMatches = false;

               var keys = Object.keys(props);
               for (var i = 0; i < keys.length; i++) {
                   var prop = keys[i];
                   var text = props[prop].toLowerCase();
                   if (item[prop].toString().toLowerCase().indexOf(text) !== -1){
                       itemMatches = true;
                       break;
                   }
                }

                if (itemMatches) {
                  out.push(item);
                }
             });
           } else {
           // Let the output be the input untouched
               out = items;
           }

           return out;
         }
    });

 //To use add this to UI-Selet Where you are using filter
 <ui-select-choices repeat="city in List | propsFilter: {name: $select.search, secondFilter: $select.search, third: $select.search} | orderBy:'sortOrder'">
Sign up to request clarification or add additional context in comments.

1 Comment

I have a similar custom filter written. But all of a sudden it has stopped working. The filter doesn't even get called.. The only thing I changed was that I deployed it onto a different server. Did you face such issue?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.