I am using the following function to make a specific filter passing the $scope.searchParams
in this way:
<tbody ng-repeat="user in users | customFilter:searchParams "> ...
$scope.updateSearch = function() {
var searchParams = {},
loginArr = [],
nameArr = [],
statusArr = [],
accountsArr = [],
profileArr = [];
if($scope.search.name !== undefined && /\S/.test($scope.search.name)){
//$scope.tags.push({ text: 'Nombre: ' + $scope.name });
nameArr.push($scope.search.name);
searchParams['name'] = nameArr;
}
if($scope.search.login !== undefined && /\S/.test($scope.search.login)){
//$scope.tags.push({ text: 'Nombre: ' + $scope.name });
loginArr.push($scope.search.login);
searchParams['login'] = loginArr;
}
if($scope.search.status !== undefined && /\S/.test($scope.search.status)){
//$scope.tags.push({ text: 'Nombre: ' + $scope.name });
statusArr.push($scope.search.status);
searchParams['merchant.status'] = statusArr;
}
if($scope.search.accounts !== undefined && /\S/.test($scope.search.accounts)){
//$scope.tags.push({ text: 'Nombre: ' + $scope.name });
accountsArr.push($scope.search.accounts);
//accountsArr.push('500092');
searchParams['merchant.accounts'] = accountsArr;
}
if($scope.search.profiles !== undefined && /\S/.test($scope.search.profiles)){
//$scope.tags.push({ text: 'Nombre: ' + $scope.name });
accountsArr.push($scope.search.profiles);
searchParams['merchant.accounts'] = accountsArr;
}
$scope.searchParams = searchParams;
};
In this case I have to filter based on 5 fields ('login','name','status','account' and 'profile'). This is not optimum if I need 10 or more fields to filter. How can I do this more generic?