How to filter the entire table with text instead of per column ng-grid 3.0 (ui-grid)

298 Views Asked by At

I looked at the docs and didn't see an easy way too accomplish this in ng-grid 3. In ng-grid 2 you could bind a text field to

$scope.filterOptions = {
   filterText: ''
};

and then in gridOptions...

$scope.gridOptions = { 
   data: 'someData',
   filterOptions: $scope.filterOptions
};

I could roll my own filtering, but I'm hoping there is a simpler way to do this that I am missing.

1

There are 1 best solutions below

0
On BEST ANSWER

Alright so I rolled my own. Here it is.

$scope.$watch('filter.filterText', function(newVal, oldVal) {
    $scope.filteredData = $scope.data.filter(function(data) {
      if (data.fullName.toLowerCase().indexOf($scope.filter.filterText) > -1 ||
          data.someField.toLowerCase().indexOf($scope.filter.filterText) > -1 ||
          data.someOtherField.toLowerCase().indexOf($scope.filter.filterText) > -1) {
        return true;
      }
      else {
        return false;
      }
    });

}, true);

$scope.filter.filterText is bound to an input box and is watched in a controller. Whenever a user modifies the text, the filteredData is updated. The ui-grid uses filteredData as its data source. Short and sweet, but I do miss the old functionality in 2.0.