fredguile / ng2-md-datatable

Angular 5+ DataTable component for using with Material Design 2
https://www.npmjs.com/package/ng2-md-datatable
MIT License
38 stars 13 forks source link

pagination: currentPage is not being updated #44

Closed grimace closed 7 years ago

grimace commented 7 years ago

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,
        });
    };
fredguile commented 7 years ago

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:

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.

fredguile commented 7 years ago

I've released v1.3.12 with this change, plz let me know if it works for you!