user3599828
user3599828

Reputation: 331

Angular UI-Grid filtering by strict match

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.

Upvotes: 4

Views: 2493

Answers (3)

Wahap
Wahap

Reputation: 141

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;             
          }
    }    
}

Upvotes: 2

Qi Tang
Qi Tang

Reputation: 1165

Try this

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

Upvotes: 8

cbender
cbender

Reputation: 2251

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"

Upvotes: 0

Related Questions