var app = angular.module('app', ['ngTouch', 'ui.grid']);

app.controller('MainCtrl', ['$scope', '$http', 'uiGridConstants', function ($scope, $http, uiGridConstants) {
  var today = new Date();
  $scope.gridOptions = {
    enableFiltering: false,
    useExternalFiltering: true,
    enableSorting:false,
    onRegisterApi: function(gridApi){
      $scope.gridApi = gridApi;
      $scope.gridApi.grid.registerRowsProcessor( $scope.singleFilter, 200 );
      $scope.gridApi.core.on.filterChanged( $scope, function() {
              var grid = this.grid;
              if( grid.columns[1].filters[0].term === 'male' ) {
                $http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/100_male.json')
                .success(function(data) {
                  $scope.gridOptions.data = data;
      
                  $scope.gridOptions.data[0].age = -5;
                  
                  data.forEach( function addDates( row, index ){
                    row.mixedDate = new Date();
                    row.mixedDate.setDate(today.getDate() + ( index % 14 ) );
                    row.gender = row.gender==='male' ? '1' : '2';
                  });
                });
              } else if ( grid.columns[1].filters[0].term === 'female' ) {
                $http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/100_female.json')
                .success(function(data) {
                  $scope.gridOptions.data = data;
      
                  $scope.gridOptions.data[0].age = -5;
                  
                  data.forEach( function addDates( row, index ){
                    row.mixedDate = new Date();
                    row.mixedDate.setDate(today.getDate() + ( index % 14 ) );
                    row.gender = row.gender==='male' ? '1' : '2';
                  });
                });
              } else {
                $http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/500_complex.json')
                .success(function(data) {
                  $scope.gridOptions.data = data;
      
                  $scope.gridOptions.data[0].age = -5;
                  
                  data.forEach( function addDates( row, index ){
                    row.mixedDate = new Date();
                    row.mixedDate.setDate(today.getDate() + ( index % 14 ) );
                    row.gender = row.gender==='male' ? '1' : '2';
                  });
                });
              }
            });
    },
    columnDefs: [
      { field: 'name' },
      { field: 'gender', cellFilter: 'mapGender' },
      { field: 'company' },
      { field: 'email' },
      { field: 'phone' },
      { field: 'age', type:'number' },
      { field: 'mixedDate' }
    ]
  };
  $http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/500_complex.json')
    .success(function(data) {
      $scope.gridOptions.data = data;
      $scope.gridOptions.data[0].age = -5;
      
      data.forEach( function addDates( row, index ){
        row.mixedDate = new Date();
        row.mixedDate.setDate(today.getDate() + ( index % 14 ) );
        row.gender = row.gender==='male' ? '1' : '2';
      });
    });
    
  $scope.filter = function() {
    $scope.gridApi.grid.refresh();
  };
  
  $scope.toggleFilter = function(){
    console.log('filtered by age');
    $scope.gridOptions.enableFiltering = !$scope.gridOptions.enableFiltering;
    $scope.gridApi.core.notifyDataChange( uiGridConstants.dataChange.COLUMN );
  };
  $scope.ageFilter = function() {
    var ageCol = $scope.gridOptions.columnDefs[5];
      console.log(ageCol);
      if ($scope.filterValueAge !== undefined)
      {
        ageCol.filter = {
          term: $scope.filterValueAge,
          //condition: function(searchTerm, cellValue) {
//            return cellValue.match(new RegExp($scope.filterValueAge));
          //}
        };
      }
      //var ageMatch = true;//($scope.filterValueAge == undefined || (row.entity['age'] === $scope.filterValueAge));
      console.log(ageCol.filter);
      $scope.gridApi.grid.refresh();
  };
    
  $scope.singleFilter = function( renderableRows ){
    var matcher = new RegExp($scope.filterValue);
    renderableRows.forEach( function( row ) {
      var match = false;
      [ 'name' ].forEach(function( field ){
        if ( row.entity[field].match(matcher)){
          match = true;
        }
      });
      console.log($scope.filterValueAge);
      if (match && $scope.filterValueAge !== undefined)
      {
        console.log($scope.filterValueAge === '');
        console.log(row.entity['age'] === $scope.filterValueAge);
        if (row.entity['age'] === $scope.filterValueAge){
          console.log('found age match');
          match = true;
        }
        else
        {
          match = false
        }
      }
      
      if (!match)
      {
        row.visible = false;
      }
    });
    return renderableRows;
  };
}])
.filter('mapGender', function() {
  var genderHash = {
    1: 'male',
    2: 'female'
  };

  return function(input) {
    if (!input){
      return '';
    } else {
      return genderHash[input];
    }
  };
});
.grid {
  width: 500px;
  height: 450px;
}
<!doctype html>
<html ng-app="app">
  <head>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular-touch.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular-animate.js"></script>
    <script src="http://ui-grid.info/docs/grunt-scripts/csv.js"></script>
    <script src="http://ui-grid.info/docs/grunt-scripts/pdfmake.js"></script>
    <script src="http://ui-grid.info/docs/grunt-scripts/vfs_fonts.js"></script>
    <script src="http://ui-grid.info/release/ui-grid.js"></script>
    <link rel="stylesheet" href="http://ui-grid.info/release/ui-grid.css" type="text/css">
    <link rel="stylesheet" href="main.css" type="text/css">
  </head>
  <body>

<div ng-controller="MainCtrl">
  Name:<input ng-model='filterValue'/><button ng-click='filter()'>Filter</button>
  <br/>
  Age:<input ng-model='filterValueAge'/><button ng-click='ageFilter()'>Filter Age</button><br/>
  <button ng-click="toggleFilter()">toggle</button>
  <div id="grid1" ui-grid="gridOptions" class="grid"></div>
</div>


    <script src="app.js"></script>
  </body>
</html>