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.
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).
You can make use of
destroy
. See here.So:
$('#pagination').twbsPagination('destroy');
Then reinitialize it:
$('#pagination').twbsPagination({totalPages:5});
Fiddle
Ah, I managed to get this work in a different way. Since I am using this in conjunction with JQGrid, I picked loadComplete event to patch my code. Here goes the steps:
1.Create a DIV to hold the paging buttons (of twbs control)
2.Crated a local js variable to hold current page
3.Update page number before AJAX of JQgrid
4.Rebuild the pagination control on loadComplete. When user clicks on a page, I am updating the page number (
currentPage
) and reloading the grid.destroy method not worked for me(1.4.1), by look into the source code i find that there are 2 key point to make it re-instantiate correctly.
above shows part of my code, hope it helps you:
Read the twbs-pagination source code
Viewstate param twbs-pagination exists, so you cannot re-render.
So you can call
destroy
method @Robin Carlo CatacutanOR manually execute inner method @Vipin Kohli