mharris717 / ember-cli-pagination

Pagination Addon for Ember CLI
MIT License
272 stars 116 forks source link

no total_pages in meta response #206

Open makz27 opened 7 years ago

makz27 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

Is this still the case in v3.0.0 ?

makz27 commented 7 years ago

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 commented 7 years ago

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 commented 5 years ago

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.

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;
  }