Two jquery pagination plugin in the same page doesn't seem to work

核能气质少年 提交于 2019-11-30 10:01:05

Since this doesn't seem to be officially supported, here is a workaround (working demo).

Step 1 Create your HTML markup as follows:

<div class="pagination" id="Pagination">
  <!-- the container for your first pagination area -->
</div>

<div id="results">
  <!-- the container where you show your results -->
</div>

<div class="pagination" id="Pagination2">
  <!-- the container for your second pagination area -->
</div>

Step 2 The idea:
The idea is now to use the pagination plugin as usual with the first pagination div. But additionally, we want to copy all contents of the first pagination div to the second pagination div every time a page change occurs.

Step 3 Tweak the pageSelect-callback:
Add the following lines at the end of your callback function:

var paginationClone = $("#Pagination > *").clone(true);
$("#Pagination2").empty();
paginationClone.appendTo("#Pagination2");

It is very important to include the boolean parameter (withDataAndEvents) with the .clone call, otherwise the copy of your pagination won't have any click events.

Now, every time you click on a pagination element (regardless if it is the original or the copy), the page will change and the pagination elements will update accordingly.

Probably this is not the answer you were hoping for, but there's a feature request for the jQuery Pagination plugin that suggest that having two pagers on the same page is not supported by the current implementation:

http://plugins.jquery.com/node/11825

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!