Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset total pages in jquery pagination plugin

I am using TwbsPagination plug in for displaying paging in my app. It is working fine when we set the page size while initializing. However, based on the search result, I want to reset the total page count.

When I try using

$('#pagination').twbsPagination({totalPages:10});

it is not resetting the total pages displayed.

like image 762
Krishna Sarma Avatar asked Jul 25 '14 17:07

Krishna Sarma


2 Answers

You can make use of destroy. See here.

So:

$('#pagination').twbsPagination('destroy');

Then reinitialize it:

$('#pagination').twbsPagination({totalPages:5});

Fiddle

like image 24
Robin Carlo Catacutan Avatar answered Sep 16 '22 14:09

Robin Carlo Catacutan


After analyzing the script code i get to know that this script uses .data() method to save view state of the pagination and i managed to do it explicitly.

.data(): Store arbitrary data associated with the matched elements or return the value at the named data store for the first element in the set of matched elements. ref: http://api.jquery.com/data/

Solution to reset pagination.

you just need to call before your "list rendering" OR "data binding" funciion / method

$('#pagination').empty();

$('#pagination').removeData("twbs-pagination");

$('#pagination').unbind("page");

and this will reset view state data of the pagination. ("twbs-pagination" is the view state key).

like image 196
Vipin Kohli Avatar answered Sep 20 '22 14:09

Vipin Kohli