Note that there are some explanatory texts on larger screens.

plurals
  1. POTable pagination - li's aren't appending correctly
    primarykey
    data
    text
    <pre><code>function pagination() { $('.paginated').each(function() { var currentPage = 0; var numPerPage = $("#instancesPerPage").val(); var $table = $(this); $table.bind('repaginate', function() { $table.find('tbody tr').hide().slice(currentPage * numPerPage, (currentPage + 1) * numPerPage).show(); }); $table.trigger('repaginate'); var numRows = $table.find('tbody tr').length; var numPages = Math.ceil(numRows / numPerPage); var $pager = $('&lt;ul&gt;&lt;/ul&gt;'); for (var page = 0; page &lt; numPages; page++) { var pageUrl = '&lt;a href="#"&gt;' + page + '&lt;/a&gt;'; $('&lt;li&gt;&lt;/li&gt;').html(pageUrl).on('click', { newPage: page }, function(event) { currentPage = event.data['newPage']; $table.trigger('repaginate'); $(this).addClass('active').siblings().removeClass('active'); }).appendTo($pager); } $pager.appendTo('#pager'); $("ul li:first-child").addClass('active'); }); }; </code></pre> <p>If my table has 8 rows and my numPerPage.value is 2 the above function will produce the following:</p> <pre><code>&lt;div class="pagination-instances pagination-small pagination-right" id="pager"&gt; &lt;ul&gt;&lt;/ul&gt; &lt;ul&gt; &lt;li class="active"&gt;&lt;a href="#"&gt;0&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;2&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;3&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </code></pre> <p>Upon calling the following function when selecting another numPerPage.value:</p> <pre><code> $('#instancesPerPage').on("change", function() { pagination(); }); </code></pre> <p>My table page changes to the correct numPerPage.value but the li's are not updated correctly and becoming a mess.</p> <pre><code>&lt;div class="pagination-instances pagination-small pagination-right" id="pager"&gt; &lt;ul&gt;&lt;/ul&gt; &lt;ul&gt; &lt;li class="active"&gt;&lt;a href="#"&gt;0&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;2&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;3&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;ul&gt; &lt;li class="active"&gt;&lt;a href="#"&gt;0&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;1&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;ul&gt; &lt;li class="active"&gt;&lt;a href="#"&gt;0&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;1&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </code></pre> <p>Apparently this has something todo with the appendTo I am using, but I have no idea how to correct that. Also I have no idea why there is a empty <code>&lt;ul&gt;&lt;/ul&gt;</code>.</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. 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