Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Calling pagination() multiple times won't work, because you're not unbinding the event and you are appending to <code>&lt;div id="pager"&gt;</code> rather than replacing the content.</p> <p>Also, if you have multiple paginated tables, they all try add a <code>ul</code> to the same <code>&lt;div id="pager"&gt;</code>. By specifying a target div for the pager in the table, you can have multiple paginated tables with multiple pagers.</p> <pre><code>&lt;select id="instancesPerPage"&gt; &lt;option value="2"&gt;2&lt;/option&gt; &lt;option value="5"&gt;5&lt;/option&gt; &lt;option value="8"&gt;8&lt;/option&gt; &lt;option value="100"&gt;100&lt;/option&gt; &lt;option value="999999999"&gt;All&lt;/option&gt; &lt;/select&gt; Instances per page &lt;table data-provide="pagination" data-pager="#pager"&gt; &lt;tr&gt;&lt;td&gt;Row 1&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;Row 2&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;Row 3&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;Row 4&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;Row 5&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;Row 6&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;Row 7&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;Row 8&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt; &lt;div class="pagination pagination-small" id="pager"&gt;&lt;/div&gt; &lt;table data-provide="pagination" data-pager="#pager2"&gt; &lt;tr&gt;&lt;td&gt;ABC 1&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;ABC 2&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;ABC 3&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;ABC 4&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;ABC 5&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;ABC 6&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;ABC 7&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;ABC 8&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt; &lt;div class="pagination pagination-small" id="pager2"&gt;&lt;/div&gt; ​ </code></pre> <p>Using js</p> <pre><code>function pagination() { $('table[data-provide=pagination]').each(function() { var $table = $(this); var $pager = $('&lt;ul&gt;&lt;/ul&gt;'); var currentPage = 0; var numPerPage = $("#instancesPerPage").val(); var numRows = $table.find('tbody tr').length; var numPages = Math.ceil(numRows / numPerPage); $table.unbind('repaginate'); $table.bind('repaginate', function() { $table.find('tbody tr').hide().slice(currentPage * numPerPage, (currentPage + 1) * numPerPage).show(); }); for (var page = 0; page &lt; numPages; page++) { var link = '&lt;a href="#"&gt;' + page + '&lt;/a&gt;'; $('&lt;li&gt;&lt;/li&gt;').html(link).on('click', { newPage: page}, function(event) { currentPage = event.data['newPage']; $table.trigger('repaginate'); $(this).addClass('active').siblings().removeClass('active'); }).appendTo($pager); } $pager.find("li:first-child").addClass('active'); $($table.data('pager')).html($pager); $table.trigger('repaginate'); }); }; pagination(); $('#instancesPerPage').on("change", function() { pagination(); }); ​ </code></pre> <p><a href="http://jsfiddle.net/gZmWh/10/" rel="nofollow">http://jsfiddle.net/gZmWh/10/</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload