1

Would it be possible to have a filter (not a unique filter but the one on top of each column) in column age1 filtering the column age2 also at the same time with an 'OR' condition ?

So for example if I filter from 20 to 21 and I should get Nives, Terry and Bishop as a result...

http://plnkr.co/Jv3zUSDK1zlzPvArmFje

{ field: 'phone', enableFiltering: false },
        { field: 'age1', filters: [
    {
      condition: uiGridConstants.filter.GREATER_THAN,
      placeholder: 'greater than'
    },
    {
      condition: uiGridConstants.filter.LESS_THAN,
      placeholder: 'less than'
    }

Thanks for your help :)

1 Answers1

-1

If you want to search an age from both 'from' and 'to', I think you are looking for the SingleFilter in UI-Grid:

http://ui-grid.info/docs/#/tutorial/321_singleFilter

Some code below to describe how to filter columns ['name', 'company', 'email']:

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

app.controller('MainCtrl', ['$scope', '$http', function ($scope, $http) {
  var today = new Date();
  $scope.gridOptions = {
    enableFiltering: false,
    onRegisterApi: function(gridApi){
      $scope.gridApi = gridApi;
      //Use singleFilter option
      $scope.gridApi.grid.registerRowsProcessor( $scope.singleFilter, 200 );
    },
    columnDefs: [
      { field: 'name' },
      { field: 'gender', cellFilter: 'mapGender' },
      { field: 'company' },
      { field: 'email' },
      { field: 'phone' },
      { field: 'age' },
      { field: 'mixedDate' }
    ]
  };

  $http.get('/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.singleFilter = function( renderableRows ){
    var matcher = new RegExp($scope.filterValue);
    renderableRows.forEach( function( row ) {
      var match = false;
      [ 'name', 'company', 'email' ].forEach(function( field ){
        if ( row.entity[field].match(matcher) ){
          match = true;
        }
      });
      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];
    }
  };
});
huan feng
  • 7,307
  • 2
  • 32
  • 56