ENH: Support table pagination (#24)

Fixes #22
This commit is contained in:
Matthew Ryan Dillon 2017-09-23 14:35:50 -07:00 committed by GitHub
parent 8309486a8a
commit 578b8daa32
11 changed files with 131 additions and 8 deletions

View file

@ -0,0 +1,41 @@
import Ember from 'ember';
const { Component, computed: { alias }, computed } = Ember;
export default Component.extend({
// ARGS
model: null,
// COMPUTED
meta: alias('model.meta'),
links: alias('model.links'),
currentPage: alias('meta.pagination.page'),
totalRecords: alias('meta.pagination.count'),
firstLink: alias('links.first'),
lastLink: alias('links.last'),
nextLink: alias('links.next'),
prevLink: alias('links.prev'),
_getPage(link) {
link = this.get(link);
if (link === null) {
return null;
}
const url = new URL(link);
return parseInt(url.searchParams.get('page'));
},
_notEqual(a, b) {
return this.get(a) !== this.get(b);
},
first: computed('firstLink', function() { return this._getPage('firstLink'); }),
last: computed('lastLink', function() { return this._getPage('lastLink'); }),
next: computed('nextLink', function() { return this._getPage('nextLink'); }),
prev: computed('prevLink', function() { return this._getPage('prevLink'); }),
notOnFirst: computed('first', 'currentPage', function() { return this._notEqual('first', 'currentPage'); }),
notOnLast: computed('last', 'currentPage', function() { return this._notEqual('last', 'currentPage'); }),
});

View file

@ -4,10 +4,11 @@ import Table from 'ember-light-table';
const { Component } = Ember;
export default Component.extend({
// ARGS
model: null,
columns: null,
table: null,
table: null,
init() {
this._super(...arguments);
const table = new Table(this.get('columns'), this.get('model'));

View file

@ -3,6 +3,9 @@ import Ember from 'ember';
const { Component } = Ember;
export default Component.extend({
// ARGS
model: null,
columns: [
{ label: 'Project', valuePath: 'project.name', },
{ label: 'Study Location', valuePath: 'studyLocation.code', },