Skip to content

Instantly share code, notes, and snippets.

@i8ramin
Created June 20, 2013 18:37
Show Gist options
  • Save i8ramin/5825377 to your computer and use it in GitHub Desktop.
Save i8ramin/5825377 to your computer and use it in GitHub Desktop.
Angular JS filter that behaves much like the built in filter one, but allows you to filter with multiple values, space separated. For example "big orange round"
(function () {
'use strict';
angular.module('ConferenceRoomApp').filter('multifilter', function ($filter) {
return function (collection, query) {
var filteredCollection = collection;
var queryTokens = query ? query.split(' ') : [query];
// user entered more than word
if (queryTokens.length > 1) {
for (var i = 0; i < queryTokens.length; i++) {
filteredCollection = $filter('filter')(filteredCollection, queryTokens[i]);
}
} else {
filteredCollection = $filter('filter')(collection, queryTokens[0]);
}
return filteredCollection;
};
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment