Created
August 27, 2014 01:35
-
-
Save tarex/e288aa58e06093d517ad to your computer and use it in GitHub Desktop.
From http://stackoverflow.com/questions/15868248/how-to-filter-multiple-values-or-operation-in-angularjs/21169596#21169596 multiple filter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myApp.filter('filterMultiple',['$filter',function ($filter) { | |
return function (items, keyObj) { | |
var filterObj = { | |
data:items, | |
filteredData:[], | |
applyFilter : function(obj,key){ | |
var fData = []; | |
if (this.filteredData.length == 0) | |
this.filteredData = this.data; | |
if (obj){ | |
var fObj = {}; | |
if (!angular.isArray(obj)){ | |
fObj[key] = obj; | |
fData = fData.concat($filter('filter')(this.filteredData,fObj)); | |
} else if (angular.isArray(obj)){ | |
if (obj.length > 0){ | |
for (var i=0;i<obj.length;i++){ | |
if (angular.isDefined(obj[i])){ | |
fObj[key] = obj[i]; | |
fData = fData.concat($filter('filter')(this.filteredData,fObj)); | |
} | |
} | |
} | |
} | |
if (fData.length > 0){ | |
this.filteredData = fData; | |
} | |
} | |
} | |
}; | |
if (keyObj){ | |
angular.forEach(keyObj,function(obj,key){ | |
filterObj.applyFilter(obj,key); | |
}); | |
} | |
return filterObj.filteredData; | |
} | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment