-
-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Labels
Description
I have an issue where more pages are requested than necessary. In this example, I only have 8 results returned from the API. my pageSize is set at 25 to fetch 25 results/page. However, it requested 6 pages worth of data, which all returned empty except the first. I'm not sure what I'm doing wrong.
template
{{#impagination-dataset
fetch=(route-action 'fetch')
on-init=(action 'initializeReadOffset')
on-object-at=(action "onObjectAt")
page-size=pageSize
as |transactions|}}
...
controller
import Ember from 'ember';
import { task, timeout } from 'ember-concurrency';
const { Controller } = Ember;
export default Controller.extend({
pageSize: 25,
setReadOffset: task(function * (dataset, offset) {
yield timeout(5);
dataset.setReadOffset(offset);
}).restartable(),
actions: {
initializeReadOffset(dataset) {
this.get('setReadOffset').perform(dataset, 0);
},
onObjectAt(dataset, index) {
this.get('setReadOffset').perform(dataset, index);
}
}
});
route
import Ember from 'ember';
export default Ember.Route.extend({
model(params) {
return this.store.findRecord('account', params.account_id);
},
actions: {
fetch(pageOffset, pageSize, stats) {
return this.store.query('transaction', {
account_id: this.get('controller.model.id'),
page: pageOffset + 1
});
}
}
});
