lundi 30 janvier 2017

EmberJs pagination, how to return to first page?

I am implementing a similar solution to How is ajax pagination handled in EmberJS? for my pagination.

How would I redirect to the initial page when someone enters a page with no data? I.e. I have 3 pages of data and someone enters ?page=4.

I've tried to alter the queryParams:

if (model.get('length') === 0) {
  this.transitionTo({queryParams: {page:'0'}});
}

This works fine, but returns the following error:

TypeError: Cannot read property 'name' of undefined
    at Class.finalizeQueryParamChange (ember.debug.js:27880)
    at Router.triggerEvent (ember.debug.js:30355)
    at Object.trigger (ember.debug.js:50524)
    at finalizeQueryParamChange (ember.debug.js:49635)
    at Router.queryParamsTransition (ember.debug.js:49008)
    at Router.getTransitionByIntent (ember.debug.js:48919)
    at Router.transitionByIntent (ember.debug.js:49026)
    at doTransition (ember.debug.js:49603)
    at Router.transitionTo (ember.debug.js:49096)
    at Class._doTransition (ember.debug.js:29999)

And also tried to alter the controller page variable:

this.controllerFor('my-controller').set('page', 0);

But the later has no effect.




Aucun commentaire:

Enregistrer un commentaire