create filtered collection from backbone collections
JavaScript CSS
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


given a collection and a filter (and optional comparator) return a collection that mimics it's parent only with a filtered set of models.


var EnhancedCollection = Backbone.Collection.extend({
	enhance: true

var myCollection = new EnhancedCollection();

var notGreenCollection = new Backbone.CollectionFilter(myCollection, function(child) {
	return child.get('color') !== 'green';

the filtered collection will inherit all functions and bind them to the original collection except on, off, trigger, at and pluck. It will even return the paramaters set on the parent collection (e.g. notGreenCollection.enhance === true) unless you set the parameter on the instance (so make sure you use setters, e.g. notGreenCollection.setEnhance(false) instead of notGreenCollection.enhance = false).


added in multifilter.js which requires CF but makes it easy to add mutiple filters on and off a collection:

var filters = {
	isGreen: function(model) {
		return model.get('color') == 'green';
	isSquare: function(model) {
		return model.get('shape') == 'square';

myCollection = Multifilter(myCollection, filters);

myCollection.addFilter('isGreen'); // now only greens will show
myCollection.addFilter('isSquare'); // now only green squares
myCollection.removeFilter('isGreen'); // now only squares



add in options simple that will only filter the changes - use only for filter functions that rely on the model change


functions are now dynamically bound, only resolve function to bind when called


  • can pass in extra events to redo filter on


  • give new events array
  • only redo fiter on certain events


-initial versioning