josecebe / twbs-pagination

jQuery pagination plugin (bootstrap powered)
http://josecebe.github.io/twbs-pagination/
Other
1.1k stars 401 forks source link

Change totalPages instead of remove the twbsPagination element and recreate it #172

Closed josecebe closed 6 years ago

josecebe commented 6 years ago

I need to refresh the pagination element, but I can't do this without removing it and creating it again. This is so annoying for me (and probably also for you).

I have created the next method:

    changeTotalPages: function(totalPages, currentPage) {
        this.options.totalPages = totalPages;
        var pages = this.getPages(currentPage);
        this.render(pages);
    },

Basically, if you want to change the total pages that is shown in the twbsPagination element, you just need to run it doing this:

50 -> New total pages

40 -> Select that page

    $paginationElement.twbsPagination("changeTotalPages", 50, 40);
guantou commented 6 years ago

nice job, i also need this.

as a pager work with ajax, somtimes we need to rerender the pager when the list result changed, such as show the list when i open a list page , and then i search the list with ajax , and it returned a new list, a new count number, the problem is this plugin will not rerender with the new data and still show the first style, maybe it should consider to support this situation.

i found this line make the TwbsPagination singleton https://github.com/esimakin/twbs-pagination/blob/9b6d2116597be3b458c7cd707a126157be5626c4/jquery.twbsPagination.js#L295

when i change it to this, it works for me . always recreate a new pager when the data source changed

$this.data('twbs-pagination', (data = new TwbsPagination(this, options) ));