Filtering by Multiple Specific Model Properties in AngularJS (in OR relationship)

前端 未结 13 2604
北恋
北恋 2020-11-22 17:08

Take a look at the example here: http://docs.angularjs.org/api/ng.filter:filter

You can search by any of the phone properties by using

13条回答
  •  鱼传尺愫
    2020-11-22 18:06

    Pretty straight forward approach using filterBy in angularJs

    For working plnkr follow this link

    http://plnkr.co/edit/US6xE4h0gD5CEYV0aMDf?p=preview

    This has specially used a single property to search against multiple column but not all.

    
    
    
      
        
        
        
        
      
    
      
      
       
    {{row.col1}} {{row.col2}} {{row.col3}}

    This will show filter from two columns only(col1 and col2) . Not from all. Whatever columns you add into filter array they will be searched. all columns will be used by default if you use filter: vm.searchText

    controller

    // Code goes here
    (function(){
    
      var myApp = angular.module('myApp',['angular.filter']);
    
      myApp.controller('myCtrl', function($scope){
        var vm= this;
        vm.x = 20;
    
        vm.tableData = [
          {
            col1: 'Ashok',
            col2: 'Tewatia',
            col3: '12'
          },{
            col1: 'Babita',
            col2: 'Malik',
            col3: '34'
          },{
            col1: 'Dinesh',
            col2: 'Tewatia',
            col3: '56'
          },{
            col1: 'Sabita',
            col2: 'Malik',
            col3: '78'
          }
          ];
      })
    
    })();
    

提交回复
热议问题