admin管理员组

文章数量:1314568

I'm creating a table with Angular UI-Grid and I wanted to filter the table contents by a strict match. By default "Car" input will match with "Carol" but I want UI-Grid's filtering to only match if the input is equal to a table entry.

I'm creating a table with Angular UI-Grid and I wanted to filter the table contents by a strict match. By default "Car" input will match with "Carol" but I want UI-Grid's filtering to only match if the input is equal to a table entry.

Share Improve this question asked Jul 28, 2015 at 17:04 user3599828user3599828 3318 silver badges14 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 8

Try this

{
        field: 'email',
        filter: {
          condition: uiGridConstants.filter.EXACT,
          placeholder: 'your email'
        } 
      }

Trying uiGridConstants.filter.EXACT causes fetching also CAR 1, CAR 2.

If you want to fetch "CAR" only, excluding "CAR 1" and "CAR 2", using a function would be useful:

{ field: 'name', width :'150', filter: {
        condition: function(searchTerm, cellValue) {
            if (searchTerm === cellValue)
               return -1;
            else 
               return 0;             
          }
    }    
}

Make a filter method. Instead of having ng-repeat="x in items|filter:filterVariable" use a filter method. In your controller code put:

var myFilter = function(x){
  return x == $scope.filterVariable;
}

and the ng-repeat would look like:

ng-repeat="x in items | filter:myFilter"

本文标签: javascriptAngular UIGrid filtering by strict matchStack Overflow