1

how can I get a filter with ng-click out of an ul as second filter for an ngtable?

<ul class="artGroups">
  <li class="" ng-repeat="artGroup in artGroups">
    <a href="#" ng-click="">{{artGroup.artGroupName}}</a>
  </li>
</ul>

Here's a plnkr: http://plnkr.co/edit/Amdx2BzEWQWVYmRAgTMw

1
  • what are you trying to filter out on ng-click()? Commented Feb 4, 2015 at 19:58

1 Answer 1

4

You can set a function on the main controller to change a value when an artGroup is selected:

$scope.selectedGroup = '';
$scope.setGroup = function(group) {
    $scope.selectedGroup = group;
}

And wire up the ng-click directive:

<a href="#" ng-click="setGroup(artGroup.artGroupId)">{{artGroup.artGroupName}}</a>

Then you can set up another custom filter on the tr, using that selectedGroup variable on the scope:

<tr ng-repeat="article in articles | filter:searchText | isArtGroup:selectedGroup">

Then create the custom filter to filter the articles based on whether or not they fall into that artGroupId:

app.filter('isArtGroup', function(){
  return function(values, groupId) {
    if(!groupId) {
      // initially don't filter
      return values;
    }
    // filter when we have a selected groupId
    return values.filter(function(value){
      return value.artGroupId === groupId;
    })
  }
})

Here's all of that working together in Plunker

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

1 Comment

In the setGroup function you can just check to see if the groupId is set to the current value, if not set it to an empty string

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.