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

no total_pages in meta response #206

Open
makz27 opened this issue Jan 19, 2017 · 5 comments
Open

no total_pages in meta response #206

makz27 opened this issue Jan 19, 2017 · 5 comments

Comments

@makz27
Copy link

makz27 commented Jan 19, 2017

Hello,

My api send me this structure

{"users":
[
...
],
"meta":
{
"pagination":
{
"total":6,
"count":6,
"per_page":10,
"current_page":1,
"total_pages":1,
"links":[]
}
}
}

Following the dummy test here's my controller

export default Ember.Controller.extend({
    queryParams: ["page","perPage"],
    page: 1,

    pageBinding: Ember.computed.oneWay("content.page")
});

and my route

import Ember from 'ember';
import RouteMixin from 'ember-cli-pagination/remote/route-mixin';

export default Ember.Route.extend(RouteMixin, {
    model: function(params) {
      return Ember.RSVP.hash({
        content: this.findPaged('user',params)
      });
    },

    setupController: function(controller, models) {
      controller.setProperties(models);
    }
});

The pagination is good, but i can click on next page even if the next page is empty (6 records on a total of 50 items, only one page)

and here's the console log

validate.js:11 no total_pages in meta response
validate.js:11 no totalPages for page-numbers
validate.js:11 no int for totalPages val is undefined
validate.js:11 no int for totalPages val is NaN
validate.js:11 no int for totalPages val is NaN

Did i miss something ?

Thank you.

EDIT

In fact, the "next arrow" have the class "disabled" but i can still click on this (maybe a simple template error), but it's always disabled even if i have a next page. maybe because totalPages is undefined.

@jeremyguarini
Copy link

jeremyguarini commented Feb 12, 2017

I also had the same issue, I ended up changing the meta to have total_pages instead of total and messages seemed to go away.

For your issue with still being able to click the disabled next button, I had the same issue. I found that I was sending over a float as the total_pages in the meta. Once I switched to int, the next button was no longer clickable once I got to the end. I would think the library would check type and convert to int if needed.

--
Jeremy

@broerse
Copy link
Collaborator

broerse commented Feb 12, 2017

Is this still the case in v3.0.0 ?

@makz27
Copy link
Author

makz27 commented Feb 14, 2017

Yep same problem for me. Maybe because my pagination is inside content->meta->pagination->total_pages

but i have no power on this, dingo/api return me this structure.

@sheshnath08
Copy link

I also had the same issue, I fixed this by normalizing the server's response, by adding this code in application's controller.

normalizeQueryResponse(store, clazz, payload) {
const result = this._super(...arguments);
result.meta.total_pages = result.meta.total_pages || {};
if (payload.meta) {
result.meta.total_pages = payload.meta.pagination.pages;
}
return result;
}

Refer here

@reggietheroman
Copy link

I also had the same issue, I fixed this by normalizing the server's response, by adding this code in application's controller.

normalizeQueryResponse(store, clazz, payload) {
const result = this._super(...arguments);
result.meta.total_pages = result.meta.total_pages || {};
if (payload.meta) {
result.meta.total_pages = payload.meta.pagination.pages;
}
return result;
}

Refer here

used the same code with some changes.

  • changed clazz to ModelClass
  • changed result.meta.total_pages = result.meta.total_pages to result.meta.pagination.total_pages

information is in meta.pagination because we use dingo

normalizeQueryResponse(store, ModelClass, payload) {
    const result = this._super(...arguments);
    result.meta.total_pages  = result.meta.pagination.total_pages || {};

    if (payload.meta) {
      result.meta.total_pages = payload.meta.pagination.total_pages;
    }
    return result;
  }

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

5 participants