0

I have the following dates select drop down.

<input type="text" ng-modle="byNameFilter"/>
<select ng-model="byDateFilter" multiple="multiple">
 <option ng-repeat="date in dates" value="{{date}}">{{date}}</option>
</select>
<div>
<repeater ng:repeat="program in programNames | filter:byNameFilter | filter:byDateFilter">
   <a href="#/client/{{client}}/program/{{program.name}}" class="span2 btn">{{program.name}}</a>
</repeater>

the program structure is:

[{'name':'program1','dates':['date1', 'date2']},{'name':'program2','dates':['date3', 'date2']}]

Now the filter is working when I put some text in ng-model:byNameFilter but It is not working when I select dates from select drop down (It is working fine if I remove multiple attribute).

How we can implement filter for multiple select options in angular.js

1
  • could you share your fiddle please Commented Apr 4, 2013 at 12:05

1 Answer 1

2

I solved it using a custom function (provided it to filter)

$scope.dateFilter = function (item)
{
    //debugger;

    if ($scope.byDateFilter === undefined || $scope.byDateFilter.length == 0)
    {
        return true;
    }   

    for (var i in $scope.byDateFilter){         

        for (var j in item.dates)
        {
            if (item.dates[j] == $scope.byDateFilter[i])
            {
                return true;
            }
        }
    }

    return false;
}

Change in html:

<repeater ng:repeat="program in programNames | filter:byNameFilter | filter:dateFilter">

Is there any other simple solution ?

Sign up to request clarification or add additional context in comments.

Comments

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.