Skip to content

Instantly share code, notes, and snippets.

@robmonie
Created September 14, 2011 03:54
Show Gist options
  • Save robmonie/1215818 to your computer and use it in GitHub Desktop.
Save robmonie/1215818 to your computer and use it in GitHub Desktop.
Sproutcore PagedArrayController
/**
* Provides paged content based on a larger result set.
*/
App.PagedArrayController = SC.ArrayProxy.extend({
content: [],
/**
* Subclasses should define the allResultsBinding to bind to the full set
* of results to be paged through
*/
allResults: [],
/*
* Must replace entire pagination object for changes to propogate.
*/
pagination: {
start: 0,
limit: 50
},
_allResultsDidChange: function() {
var results = this.get('allResults'),
pagination = this.get('pagination'),
lastIndex = pagination.start + pagination.limit,
allResultsLength = this.get('allResults').get('length');
if(lastIndex > allResultsLength) {
lastIndex = allResultsLength;
}
this.set('content', results.slice(pagination.start, lastIndex));
}.observes('*allResults.[]', 'pagination')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment