pagination: currentPage is not being updated
grimace opened this issue · 2 comments
if I make these changes in : md-datatable-pagination.component.js, then it starts to work
MdDataTablePaginationComponent.prototype.onClickFirst = function () {
this.currentPage = 1; // <--- update the page before emit
this.paginationChange.emit({
page: 1,
itemsPerPage: this.itemsPerPage,
});
};
MdDataTablePaginationComponent.prototype.onClickLast = function () {
var lastPage = Math.ceil(this.itemsCount / this.itemsPerPage);
this.currentPage = lastPage; // <--- update the page before emit
this.paginationChange.emit({
page: lastPage,
itemsPerPage: this.itemsPerPage,
});
};
MdDataTablePaginationComponent.prototype.onClickPrevious = function () {
this.currentPage = this.currentPage-1; // <--- update the page before emit
this.paginationChange.emit({
page: this.currentPage,
itemsPerPage: this.itemsPerPage,
});
};
MdDataTablePaginationComponent.prototype.onClickNext = function () {
this.currentPage = this.currentPage+1; // <--- update the page before emit
this.paginationChange.emit({
page: this.currentPage,
itemsPerPage: this.itemsPerPage,
});
};
Okay I get your point. I'll test this out, but feel free to experiment this change in a fork too.
So far it was working similar to the Flux pattern:
- onClickFirst, onClickLast, onClickPrevious, onClickNext emit events in a fire-and-forget manner => they don't update the pagination UI.
- events get subscribed by the model which loads the datasource using the specified pagination parameters, returning the specified page with updated pagination values.
- these values are passed as Input() to the pagination component, which update its UI when they change.
If you recreate this Flux loop View => Action => Dispatcher => Service => Model => UI, you gonna have the pagination UI updating. So far it seems that not many people were complaining about this approach.
In your case, you want to update the UI as soon as we click on first/previous/next/last, which in some ways will work, but can also triggers unwanted side-effects, that's why I would argue to test this out before changing the lib. For instance in one of my view, I've got one datatable surrounded by two pagination components that must be in sync.
I've released v1.3.12 with this change, plz let me know if it works for you!