Filter by multiple columns with ng-repeat

前端 未结 8 1721
小鲜肉
小鲜肉 2020-11-30 12:16

I\'m wondering if there\'s an easy way in Angular to filter a table using ng-repeat on specific columns using or logic, rather than and

8条回答
  •  庸人自扰
    2020-11-30 13:05

    I figured it out- I had to write my own custom filter. Here is my solution:

    var filteredData;
    
    filteredData = $filter('filter')(data, function(data) {
      if ($scope.filter) {
        return data.id.toString().indexOf($scope.filter) > -1 || data.name.toString().indexOf($scope.filter) > -1;
      } else {
        return true;
      }
    });
    

提交回复
热议问题