0

I will have an array when the user multi choose 'Author' from peoplepicker.when they choose a people,I want to filter the array with the corresponding DisplayText using ng-repeat="item in filteredart =(filteredArticles |filter: AuthorArray ")

So Now I can filter the array with a single value like $scope.AuthorArray="sridhar".but I cant filter with multiple values $scope.AuthorArray="sridhar,Alan".

Help me, I'm new :)

1
  • It's not clear what you're trying to filter. What does the array of values you are trying to filter look like? Please provide more code/context for your question. Commented Mar 28, 2016 at 13:24

2 Answers 2

1

I am not clearly getting your question but as far as I understood it, I think what you need is to write a custom filter.

In this example, matchMyCriteria matches all items in the array with the list of available names in AuthorArray array.

HTML:

<div ng-repeat="item in items | filter: matchMyCriteria()">
{{ item }}
</div>

JS:

$scope.items = [{title: "abc", author: "Alan", .....}, ......];
$scope.AuthorArray = ["sridhar", "Alan"];
$scope.matchMyCriteria = function() {
  return function(item) {
    return ($scope.AuthorArray.indexOf(item.author) > -1);
  };
};

There is another solution for it and I assume it to be the good one.

In this example, myFilter is used to filter the array of items on the basis of an array of authors.

HTML:

<div ng-repeat="item in items | myFilter: AuthorArray">
    {{item}}
</div>

JS:

app.filter('myFilter', function() {
  return function(list, criteria) {
    return list.filter(function(l) {
      return (criteria.indexOf(l.author) > -1);
    });
  };
});
Sign up to request clarification or add additional context in comments.

Comments

0

Actually I have used other method which I know.But instead of using filter on ng-repeat I used a button to trigger the filter. Thanks :)

`

 $scope.authorChange = function () {
            var ppick = SPClientPeoplePicker.SPClientPeoplePickerDict.peoplePickerDiv_TopSpan;
            var filteredArticlestemp = [];
            $scope.authorarray= getUsers(ppick);
            //$scope.authorarray = $scope.authorarray.join();
            for (var j = 0; j < $scope.authorarray.length; j++) {
                for (var i = 0; i < $scope.filteredArticles.length; i++) {
                    if ($scope.filteredArticles[i].Author == $scope.authorarray[j]) {
                        filteredArticlestemp.push($scope.filteredArticles[i]);
                    }
                }
            }
            $scope.filteredArticles = filteredArticlestemp;
        }
        function getUsers(peoplePicker) {

            // Get information about all users.
            var users = peoplePicker.GetAllUserInfo();
            var userInfo = [];
            if (users.length > 0) {
                for (var i = 0; i < users.length; i++) {
                    var user = users[i];
                    userInfo.push(user.DisplayText);

                }
            }


            return userInfo;
        }

`

`<div id="peoplePickerDiv" ng-model="authorsearch"></div>
 <input type="button" value="Refine" ng-click="authorChange()" />`

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.