-->

How to filter the NG-Grid by dropdown values

2019-08-16 04:37发布

问题:

I have a drop down menu which get populated from Nggrid Column. The dropdown is a separate control.

I want to filter the NG-grid based on the value selected from drop down value. How do I do this?

回答1:

you could add an ng-change to your select like this:

select(ng-model="search", ng-options="data in datas", ng-change='myfilter()')

and in your controller:

$scope.myfilter = function() {
   $scope.datas = $filter('filter')($scope.datas, {data.YourField: $scope.search});
    // or:
    // $scope.datas = $scope.datas.filter(function(data) {
    //    return data.YourField == search || data.YourOther == search;
    // }
};