1

I'm trying to implement pagination on my project using ember-cli-pagination but it's not working. I have something like this in the controller:

import Ember from 'ember';
import pagedArray from 'ember-cli-pagination/computed/paged-array';

export default Ember.Controller.extend({
  // 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 
  page: 1,
  perPage: 10,

  // can be called anything, I've called it pagedContent 
  // remember to iterate over pagedContent in your template 
  pagedContent: pagedArray('car', {pageBinding: "page", perPageBinding: "perPage"}),

  // binding the property on the paged array 
  // to a property on the controller 
  totalPagesBinding: "pagedContent.totalPages"
});

In the documentation, where I've put car is named content. I imagine it's an array of the objects I want to paginate.

The project is here https://github.com/mcand/contazul-frontend-test/tree/emberdata at emberdata branch.

I would appreciate if anyone could help me out.

andrefurquin
  • 502
  • 6
  • 17

1 Answers1

0

I do not have great experience with this add-on, and I haven't extensively gone through your code.

I think your problem is the fact you are binding pagedArray to 'car' instead of 'model' or 'content' because I don't see where you have defined the 'car' computed property on that controller.

So you would want:

pagedArray('content', {pageBinding: "page", perPageBinding: "perPage"})

Also, you may want the CarsController to extend ArrayController instead of Controller.

GManProgram
  • 161
  • 2
  • 11
  • I'm having this error: "ember.debug.js:3894 Uncaught TypeError: Cannot read property 'extend' of undefined" when I extend ArrayController. I haven't found any info about ArrayController in Ember 2, only in a previous version. – andrefurquin Jan 30 '17 at 22:23
  • It seems ArrayController is deprecated according to the creator of the addon. You have to use Controller instead. It's still not working, I'll try to figure out why. – andrefurquin Jan 31 '17 at 12:53
  • Even with change the pagedArray('car'..., ) to pagedArray('content', ..)? You could also try pagedArray('model', ...) though I don't think if content worked, changing it to model will work – GManProgram Jan 31 '17 at 18:31