Filter by multiple columns with ng-repeat

前端 未结 8 1717
小鲜肉
小鲜肉 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:06

    Easily We can do this type Following written code according you will easily create another field filter....

    var myApp = angular.module('myApp',[]);
    
    myApp.filter('myfilter',myfilter);
    
    function myfilter(){
       return function (items, filters) {
            
            if (filters == null) {
                return items;
            }
    
            var filtered = [];
            //Apply filter
            angular.forEach(items, function (item) { 
                if ((filters.Name == '' || angular.lowercase(item.Name).indexOf(angular.lowercase(filters.Name)) >= 0) 
                   )
                {
                    filtered.push(item);
                }
    
            });
            return filtered;
        };
    }
    
    myApp.controller('mycontroller',['$scope',function($scope){
      $scope.filters={Name:'',MathsMarks:''};
      $scope.students=[];
      var i=0;
      for(i=0;i<5;i++){
        var item={Name:'',Marks:[]};
      
        item.Name='student' + i;  
        item.Marks.push({Maths:50-i,Science:50 +i});
        
        $scope.students.push(item);
      }
    
    }]);
    
      
    
    
      
        
        
    Name : {{student.Name}} Marks == > Maths:{{m.Maths}} Science:{{m.Science}}

提交回复
热议问题