Last active
July 31, 2020 16:48
-
-
Save gokatz/30bd47e70fdce3ca98feef25753a85c3 to your computer and use it in GitHub Desktop.
ember pagination
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
| import Controller from "@ember/controller"; | |
| import { tracked } from "@glimmer/tracking"; | |
| import { alias, oneWay } from "@ember/object/computed"; | |
| import pagedArray from "ember-cli-pagination/computed/paged-array"; | |
| import { inject as service } from '@ember/service' | |
| export default class ArticlesController extends Controller { | |
| // setup our query params | |
| queryParams = ["page", "perPage"]; | |
| // set default values, can cause problems if left out | |
| // if value matches default, it won't display in the URL | |
| @tracked page = 1; | |
| @tracked perPage = 5; | |
| // can be called anything, I've called it pagedContent | |
| // remember to iterate over pagedContent in your template | |
| @pagedArray('model', { | |
| page: alias("parent.page"), | |
| perPage: alias("parent.perPage"), | |
| }) | |
| pagedContent; | |
| // binding the property on the paged array | |
| // to a property on the controller | |
| @oneWay("pagedContent.totalPages") totalPages; | |
| } |
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
| import Route from '@ember/routing/route'; | |
| export default Route.extend({ | |
| model() { | |
| return window.fetch('https://jsonplaceholder.typicode.com/posts') | |
| .then(res => res.json()); | |
| } | |
| }); |
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
| body { | |
| margin: 12px 16px; | |
| font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
| font-size: 12pt; | |
| } | |
| .pagination li { | |
| list-style: none; | |
| display: inline; | |
| margin: 0 3px; | |
| } |
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
| { | |
| "version": "0.17.1", | |
| "EmberENV": { | |
| "FEATURES": {}, | |
| "_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false, | |
| "_APPLICATION_TEMPLATE_WRAPPER": true, | |
| "_JQUERY_INTEGRATION": true | |
| }, | |
| "options": { | |
| "use_pods": false, | |
| "enable-testing": false | |
| }, | |
| "dependencies": { | |
| "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js", | |
| "ember": "3.18.1", | |
| "ember-template-compiler": "3.18.1", | |
| "ember-testing": "3.18.1" | |
| }, | |
| "addons": { | |
| "@glimmer/component": "1.0.0", | |
| "ember-cli-pagination": "3.1.5" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment