0

I am trying to filter few records based on a list that is in my UI. But I am querying the DB where I am getting extra details other than what I am displaying in UI. How can I restrict my search to only to the properties of object which I am displaying in UI.

eg. I am querying DB and getting firstName,lastName,age and marks . but In UI I am only displaying the firstName and marks,So When in search box I write lastName it should not display anything.

1
  • So what have you tried so far? Make some research, try some code and ask again where you fail. Commented Jun 11, 2014 at 11:56

2 Answers 2

1

The filter filter in angularjs may take an object as its filter expression:

<li ng-repeat="item in list | filter:{firstname : searchtext}">

this returns only items where the firstname property contains the searchtext.

See: https://docs.angularjs.org/api/ng/filter/filter for more information

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

2 Comments

Hi Nikolas, Thanks for reply.the filter i am trying to use comprise of both the firstname and marks.
you can use a comparator function for more complex filtering. in your controller you define: $scope.comparatorFn = function (actual, expected) { return (actual.firstname.indexOf(expected) !== -1) || (actual.marks.indexOf(expected) !== -1); }; and in the view you use the comparator function as: <li ng-repeat="item in list | filter:earchtext:comparatorFn">
0
ng-repeat="obj.firstName for obj in objects"

In your ng-repeat show only the fields you want using obj.firstName

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.