【问题标题】:table sorter pager not working with multiple tables in page. Only 1st 10 item visible表格分页器分页器不适用于页面中的多个表格。只有第 10 个项目可见
【发布时间】:2014-01-14 19:58:20
【问题描述】:
【问题讨论】:
标签:
twitter-bootstrap-3
tablesorter
【解决方案1】:
我想我在tablesorter issue 中回答了你的问题。基本上,确保每个寻呼机为其指定的表都有一个唯一的名称。
<table class="table1">...<table>
<div class="pager1">...</div>
<table class="table2">...<table>
<div class="pager2">...</div>
然后分别初始化每个表
$(".table1").tablesorter().tablesorterPager({ container: '.pager1' });
$(".table2").tablesorter().tablesorterPager({ container: '.pager2' });
【解决方案2】:
我对同样的问题感到震惊,因为我总是关心尽可能通用,所以我编写了这个简单的代码,它为表格提供 ID,按照它们在代码中出现的编号,并将特定的寻呼机应用于他们每个人。
JS
$(".tablesorter table").each(function(pageTableCount){
// Check if pageTableCount was initialized, and add 1 to its value
pageTableCount !==null ? pageTableCount++ : 1;
// Get the table and add ID with counter
table = $(this);
table.attr("id","table-sorter-"+pageTableCount);
// Does the same with the pager
pager = table.parent().find(".tablesorter-pager");
pager.attr("id","table-sorter-pager-"+pageTableCount);
// Initiate the tablesorter
table.tablesorter()
.tablesorterPager({
container: "#table-sorter-pager-"+pageTableCount
});
});
HTML (BS + FontAwesome)
<div class="table-responsive tablesorter">
<table class="table">
<thead>
<tr>
...
</tr>
</thead>
<tbody>
<tr>
...
</tr>
</tbody>
</table>
<div class="tablesorter-pager">
<a href="#" class="first btn btn-default btn-sm btn-icon"><i class="fa fa-angle-double-left"></i></a>
<a href="#" class="prev btn btn-default btn-sm btn-icon"><i class="fa fa-angle-left"></i></a>
<span class="pagedisplay"></span>
<a href="#" class="next btn btn-default btn-sm btn-icon"><i class="fa fa-angle-right"></i></a>
<a href="#" class="last btn btn-default btn-sm btn-icon"><i class="fa fa-angle-double-right"></i></a>
</div><!-- tablesorter-pager -->
</div><!-- .table-responsive -->
希望对你有帮助。
【解决方案3】:
【讨论】:
-
请注意 link-only answers 是不鼓励的,所以答案应该是寻找解决方案的终点(与另一个中途停留的参考相比,随着时间的推移往往会变得陈旧)。请考虑在此处添加独立的概要,并保留链接作为参考。