角度材料数据表搜索过滤器

时间:2017-02-27 19:02:52

标签: angularjs angular-material angular-filters

我正在尝试将动态角度过滤器应用于md数据表以搜索网格上的数据。但是它似乎没有在这里工作是我想要完成的一个小例子:

    <md-input-container>
      <label> Search Table </label>
       <input  ng-model="filter.search"> 
    </md-input-container>

  <tr md-row md-select="dessert" md-auto-select ng-repeat="dessert in desserts.data | filter: filter.search | orderBy: query.order | limitTo: query.limit : (query.page -1) * query.limit">

1 个答案:

答案 0 :(得分:2)

正如您所示,我正在添加自定义过滤器,这将按照您的描述进行。

这是自定义过滤器。

$scope.filters = [];
$scope.$watch('filter.search', function(newValue, oldValue) {
 if(newValue != undefined){
  $scope.filters = newValue.split(" ");
 }
})

$scope.searachData = {};

$scope.customSearch = function(item) {
$scope.searachData.status = true;

angular.forEach($scope.filters, function(value1, key) {
  $scope.searachData.tempStatus = false;
  angular.forEach(item, function(value2, key) {
    var dataType = typeof(value2);

    if(dataType == "string" && (!value2.includes('object'))){
      if(value2.toLowerCase().includes(value1)){
        $scope.searachData.tempStatus = true;
      }
    }else if(dataType == "object"){
      var num = value2.value.toString();
      if(num.includes(value1)){
        $scope.searachData.tempStatus = true;
      }
    }
  });
          $scope.searachData.status = $scope.searachData.status & $scope.searachData.tempStatus;
});

return $scope.searachData.status;
};

这是工作Example