简体   繁体   English

Angular UI-Grid过滤严格匹配

[英]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. 我正在使用Angular UI-Grid创建一个表,我希望通过严格匹配来过滤表内容。 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. 默认情况下,“Car”输入将与“Carol”匹配,但我希望UI-Grid的过滤仅在输入等于表条目时才匹配。

Try this 尝试这个

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

Trying uiGridConstants.filter.EXACT causes fetching also CAR 1, CAR 2. 尝试uiGridConstants.filter.EXACT会导致获取CAR 1,CAR 2。

If you want to fetch "CAR" only, excluding "CAR 1" and "CAR 2", using a function would be useful: 如果你只想获取“CAR”,不包括“CAR 1”和“CAR 2”,使用一个函数会很有用:

{ 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. 而不是使用ng-repeat="x in items|filter:filterVariable"使用过滤方法。 In your controller code put: 在您的控制器代码中:

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

and the ng-repeat would look like: 并且ng-repeat看起来像:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM