1

enter image description here

I am new the angular, what I am trying to do is applying filter on inner array of an object from table row, filter is working but works only for that td, not for the entire row, why is this happening, is there anything missing here? Any help is much appreciated.

plunker here: http://plnkr.co/edit/lXxTS1A3zRCk6mdtw2JP?p=preview

1

2 Answers 2

1

Use a filter function to pipe a second filter to your Project list: http://plnkr.co/edit/ydKDEUUWZcI0Qt9fQxhB?p=preview

$scope.applyToTitle = function (title)
  {
    if($scope.support.code.length !== 0)
    {
      for(var i=0; i<$scope.tableObject.length; i++)
      {
        for(var j=0; j<$scope.tableObject[i].details.length; j++)
        {
          if(title.details[j].code == $scope.support.code)
          {
            return title;
          }
        }
      }
    }
    else
    {
      return title;
    }
  }

And apply this filter by piping it after filter:search:

<tr ng-repeat="item in tableObject | filter:search | filter: applyToTitle">
        <td>{{item.title}}</td>
...
Sign up to request clarification or add additional context in comments.

4 Comments

thank you, is there a certain limit that we can apply filters for ng-repeat? i never knew that...
I don't think so just keep using the pipe and add more. Though the results from the previous filter will be used as the input on the next one - similar to a unix pipe.
Ok, one last thing what if i want to apply filter on subApp instead of code?, i've tried replacing code to subApp in app.js, doesn't work, any idea why?
You need a filter on each list both "item in tableObject" and "i in item.details". I have made a plunker that searches only subApp: plnkr.co/edit/mO347HdnU7ibHR05rhHx?p=preview please take notice that you need a filter for each column and both must be updated!
0

You should apply the filter to the correct field where is associated your ng-model. So instead of:

<tr ng-repeat="item in tableObject | filter:search">

It should be for example:

<tr ng-repeat="item in tableObject | filter:search.title">

5 Comments

thank you for your time, that works perfectly fine even if i mention title or not but the problem is when i type letter N in other second input, the table lists me those records which has letter N and the record with Y in the first field. please see pic above in question, i want the records with letter Y to be removed.
and you want just exact matches?
Yes, table should only show those records based on the user inputs(might be Y or N or something)
yes but the second filter is creating the issue here. What's the behavior you would like to achieve? if you remove the inner filter, you will see that the code I posted above, actually filters the rows correctly.
what i want is applying filters on the table should only show those records, lets say you search for 'ProjectD', only those records will show in the table, likewise for second field as well, when you search for Y only those records with code as Y. In the above pic i have searched for letter N and should only those records with subApp codes with N, in this case ProjectA and Project B should not appear in the table. Hope you get it now

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.