Reset total pages in jquery pagination plugin

Krishna Sarma picture Krishna Sarma · Jul 25, 2014 · Viewed 16.5k times · Source

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.

Answer

Vipin Kohli picture Vipin Kohli · Aug 4, 2014

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).