Created
September 14, 2011 03:54
-
-
Save robmonie/1215818 to your computer and use it in GitHub Desktop.
Sproutcore PagedArrayController
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
/** | |
* 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