josecebe / twbs-pagination

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

api methods #168

Closed mansoor-omrani closed 6 years ago

mansoor-omrani commented 6 years ago

Hi

It seems you need to destroy the pager and create a new instance whenever you want to set current page.

I think setting current page is just a matter of switching class='active' among anchor elements on page numbers.

Wouldn't it better to provide a method for the pager to satisfy this need? Something like below:

$('#myPager').twbsPagination('goto', 5);

This can be extended and more api methods could be provided for the pager.

$('#myPager').twbsPagination('totalPages', 25);
$('#myPager').twbsPagination('goto', 'first');
$('#myPager').twbsPagination('goto', 'last');
$('#myPager').twbsPagination('goto', 'next');
$('#myPager').twbsPagination('goto', 'prev');
josecebe commented 6 years ago

You can do this with the new method 'changeTotalPages':

$('#myPager').twbsPagination('changeTotalPages', 30, 1);

Where 30 is the new totalPages value and 1 is the new selected page.

At the moment this method is available in 'master', and soon it will be at 1.4.2 tag. (August 1, 2018).