ember-cli-pagination
ember-cli-pagination copied to clipboard
Change sort direction Remote Paginated API
I added param "sort" to queryParams, observer for sort and use setOtherParam('sort', this.get('sort')) when sort is changed. But request is happening only first time. I`d like request is happen every time sort is changed. I saw source code of paged-remote-array.js and found this code:
pageChanged: Ember.observer("page", "perPage", function() {
var page = this.get('page');
var lastPage = this.get('lastPage');
if (lastPage != page) {
this.set('lastPage', page);
this.set("promise", this.fetchContent());
}
}),
LastPage prevent to send new request. This behaviour is observed in dummy app too.
I will have to take a closer look but it seems observing 'page','perPage','paramMapping','paramsForBackendCounter','zeroBasedIndex'
and not just 'page','perPage'
would solve this.
@mixonic Do you use this module with remote API. What do you think about this issue?
@broerse I'm only maintaining a project using this library, I'm not super familiar with the ins-and-outs of the API.
Generally the issue observing a ton of things is that you will cause a lot of a) book-keeping to occur, which is unavoidable if you use observers an b) the observer function will run many times, for example when each of those things is set
.
My suggestion would be to observe all the things you want but schedule only a single fetchContent
call after all of the observer functions fire.
pageChanged: Ember.observer(
'page', 'perPage', 'paramMapping', 'paramsForBackendCounter', 'zeroBasedIndex',
function() {
if (!this._pageChangedScheduled) {
this._pageChangedScheduled = true;
Ember.run.schedule('actions', () => {
this._pageChangedScheduled = false;
let page = this.get('page');
let lastPage = this.get('lastPage');
if (lastPage !== page) {
this.set('lastPage', page);
this.set('promise', this.fetchContent());
}
});
}
}),