Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Ember.PaginationSupport

View pagination_support.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
var get = Ember.get;
 
/**
@extends Ember.Mixin
Implements common pagination management properties for controllers.
*/
Ember.PaginationSupport = Ember.Mixin.create({
/**
*/
total: 0,
 
/**
*/
rangeStart: 0,
 
/**
*/
rangeWindowSize: 10,
 
/**
*/
rangeStop: Ember.computed('total', 'rangeStart', 'rangeWindowSize', function() {
var rangeStop = get(this, 'rangeStart') + get(this, 'rangeWindowSize'),
total = get(this, 'total');
if (rangeStop < total) {
return rangeStop;
}
return total;
}).cacheable(),
 
/**
*/
page: Ember.computed('rangeStart', 'rangeWindowSize', function() {
return (get(this, 'rangeStart') / get(this, 'rangeWindowSize')) + 1;
}).cacheable(),
 
/**
*/
totalPages: Ember.computed('total', 'rangeWindowSize', function() {
return Math.ceil(get(this, 'total') / get(this, 'rangeWindowSize'));
}).cacheable(),
 
/**
*/
hasPrevious: Ember.computed('rangeStart', function() {
return get(this, 'rangeStart') > 0;
}).cacheable(),
 
/**
*/
hasNext: Ember.computed('rangeStop', 'total', function() {
return get(this, 'rangeStop') < get(this, 'total');
}).cacheable(),
 
/**
*/
didRequestRange: Ember.K,
 
/**
*/
nextPage: function() {
if (get(this, 'hasNext')) {
this.incrementProperty('rangeStart', get(this, 'rangeWindowSize'));
}
},
 
/**
*/
previousPage: function() {
if (get(this, 'hasPrevious')) {
this.decrementProperty('rangeStart', get(this, 'rangeWindowSize'));
}
},
 
rangeDidChange: Ember.observer(function() {
this.didRequestRange(get(this, 'rangeStart'), get(this, 'rangeStop'));
}, 'rangeStart', 'rangeStop')
});

@tchak Do you have an example of using this mixin?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.