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

Ember CLI Pagination integration #101

Merged
merged 2 commits into from
Jun 10, 2015
Merged

Conversation

citmusa
Copy link
Contributor

@citmusa citmusa commented Jun 10, 2015

Documentation for integrating with Ember CLI Pagination addon

@dustinfarris
Copy link
Owner

Nice! Thanks for putting this together!

dustinfarris added a commit that referenced this pull request Jun 10, 2015
Ember CLI Pagination integration
@dustinfarris dustinfarris merged commit 391d629 into dustinfarris:master Jun 10, 2015
@benkonrath
Copy link
Collaborator

@citmusa I wasn't able to get the pagination working with these instructions. Which version of Ember Django Adapter, Ember, Ember Data and Ember CLI Pagination worked for you? I'd like to add the version numbers to the documentation so people using different versions know they might have issues. Thanks.

@benkonrath
Copy link
Collaborator

@citmusa Scratch that. I just got it work. I didn't follow all of the steps from ember cli pagination. Thanks for your contribution.

@rinti
Copy link

rinti commented Jul 9, 2015

This is almost exactly what I did to get Ember Infinity working, when I get to work I can see if there's any difference, Otherwise I might add some info about that too.

@benkonrath
Copy link
Collaborator

Yeah, that would be useful. In the meantime I've figured out that the custom pagination class is not required because you can calculate the total pages with the available information.

import Ember from 'ember';
import DRFSerializer from './drf';

export default DRFSerializer.extend({
  extractMeta: function(store, type, payload) {
    if (payload && payload.results) {
      let nextPageNum = this.extractPageNumber(payload.next);
      let prevPageNum = this.extractPageNumber(payload.previous);
      let totalPages = 1;
      if (!Ember.isNone(nextPageNum)) {
        // Any page that is not the last page.
        totalPages = Math.ceil(payload.count/payload.results.length);
      } else if (Ember.isNone(nextPageNum) && !Ember.isNone(prevPageNum)) {
        // The last page when there is more than one page.
        totalPages = prevPageNum + 1;
      }

      // Sets the metadata for the type.
      store.setMetadataFor(type, {
        count: payload.count,
        next: nextPageNum,
        previous: prevPageNum,
        total_pages: totalPages
      });

      // Keep ember data from trying to parse the metadata as a records
      delete payload.count;
      delete payload.next;
      delete payload.previous;
    }
  }
});

@benkonrath
Copy link
Collaborator

I updated the example to take some edge cases into account. I may make a PR for the docs with this example.

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

Successfully merging this pull request may close these issues.

4 participants