Created
March 28, 2020 00:54
-
-
Save mastastealth/6f40e0310e83e27c31e4282489b544d7 to your computer and use it in GitHub Desktop.
Pagination Fix
This file contains 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
import Controller from '@ember/controller'; | |
import { action } from '@ember/object'; | |
export default class ApplicationController extends Controller { | |
shared = { | |
page: 0, | |
pageUI: 1, | |
pageCount: 10, | |
startIndexAtZero: true | |
} | |
@action | |
setPage(pg) { | |
//this.set('shared', null); | |
this.set('shared', { | |
page: pg - 1, | |
pageUI: pg, | |
pageCount: 10, | |
startIndexAtZero: true | |
}); | |
console.log(this.shared); | |
} | |
} |
This file contains 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
import Component from '@glimmer/component'; | |
import { tracked } from '@glimmer/tracking'; | |
import { action } from '@ember/object'; | |
import { debug } from '@ember/debug'; | |
export default class extends Component { | |
get page() { return this.args.shared?.page; } | |
get startIndexAtZero() { return this.args.shared?.startIndexAtZero; } | |
get pageCount() { return this.args.shared?.pageCount; } | |
@tracked pageNumber = this.args.shared?.pageUI; | |
get startIndex() { return (this.startIndexAtZero) ? 0 : 1; } | |
get hasNextPage() { | |
if (this.pageCount) { | |
return (this.startIndexAtZero) ? | |
this.page < this.pageCount - 1 : | |
this.page < this.pageCount; | |
} | |
return false; | |
} | |
get hasPrevPage() { return this.page > this.startIndex; } | |
get hasNoNextPage() { return !this.hasNextPage; } | |
get hasNoPrevPage() { return !this.hasPrevPage; } | |
@action | |
firstPage() { | |
debug('First page.'); | |
this.args.setPage(1); | |
this.pageNumber = 1; | |
} | |
@action | |
prevPage() { | |
debug('Previous page.'); | |
this.args.setPage(this.pageNumber - 1); | |
this.pageNumber = this.pageNumber - 1; | |
} | |
@action | |
nextPage() { | |
debug('Next page.'); | |
this.args.setPage(this.pageNumber + 1); | |
this.pageNumber = this.pageNumber + 1; | |
} | |
@action | |
lastPage() { | |
debug('Last page.'); | |
this.args.setPage(this.pageCount); | |
this.pageNumber = this.pageCount; | |
} | |
} |
This file contains 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
{ | |
"version": "0.17.0", | |
"EmberENV": { | |
"FEATURES": {}, | |
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": true, | |
"_APPLICATION_TEMPLATE_WRAPPER": true, | |
"_JQUERY_INTEGRATION": true | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"@glimmer/tracking": "^1.0.0", | |
"ember": "3.17.0", | |
"ember-template-compiler": "3.17.0", | |
"ember-testing": "3.17.0" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0", | |
"ember-truth-helpers": "2.1.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment