Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How could I get the current page number when paginating? #161

Open
rodolfojcj opened this issue Jun 22, 2016 · 4 comments
Open

How could I get the current page number when paginating? #161

rodolfojcj opened this issue Jun 22, 2016 · 4 comments

Comments

@rodolfojcj
Copy link

Hi, thanks for contributing this useful Ember adapter!

I'm playing with integrating a project of mine based on DRF 3.3.3 and Ember.js with Ember Data 2.6.0 and ember-django-adapter 1.1.2.

Right now in an HBS template file that lists the instances of some given model I have something like this:

  {{#if model.meta.previous}}
    {{#link-to 'cars' (query-params page=model.meta.previous)}}Go Previous{{/link-to}}
  {{/if}}
  {{#if model.meta.next}}
    {{#link-to 'cars' (query-params page=model.meta.next)}}Go Next{{/link-to}}
  {{/if}}

However, I would like to know how to do something like this in the same HBS template file:

Your current page is: {{model.meta.WHAT_COULD_I_USE_HERE?}}

Thanks in advance for your time and attention.

@rodolfojcj
Copy link
Author

By the way, I have another question.

Besides having a variable with the value of the current page number when paginating, do you foresee another way to get a link to each individual page available in the full pagination set? I mean, something like the example showed at Displaying links to individual page numbers.

Note: for the backend side provided by DRF 3.3.3 I'm using the PageNumberPagination class.

Again, thanks a lot!

@rmharrison
Copy link

Following Django Paginator, Page.number --> meta.number would be a sensible serialisation.

Unfortunately, the default django adapter doesn't support number (only next, previous).

The easiest work-around would be to manually include number in meta from within Ember. Can either grab from the query param, or compute from next/previous. Close example is in the docs.

Something like...

export default DRFSerializer.extend({
  extractMeta: function(store, type, payload) {
    let meta = this._super(store, type, payload);
    if (!Ember.isNone(meta)) {
        if ( (meta.next-1) == meta.previous +1 )
            meta['number'] = meta.next-1;
    }
    return meta;
  }
});

Has this workaround been sufficient for folks?

What's the feeling about including number as a computed property?

@benkonrath
Copy link
Collaborator

It makes sense to me that we include the current page number as a computed property. I'm a bit out of the loop on this project these days so I'll defer the final decision to @dustinfarris. If he agrees, then you're welcome to make a PR to add the feature.

@dustinfarris
Copy link
Owner

I like it! PR would be welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants