Note that there are some explanatory texts on larger screens.

plurals
  1. POlittle issue in jquery paging code
    primarykey
    data
    text
    <p>I've been working for a while to make this code works perfect. so I did everything works good except for the paging buttons I'm afraid that I have to post the whole code here:</p> <pre><code>$(document).ready(function() { var pager = new Pager('comments', 3); pager.init(); pager.showPageNav('Pager', 'pageNavPosition'); pager.showPage(3); function Pager(class_name, itemsPerPage) { this.class_name = class_name; this.itemsPerPage = itemsPerPage; this.currentPage = 1; this.pages = 0; this.inited = false; this.showRecords = function(from, to) { var rows = $('.' + class_name); // i starts from 1 to skip table header row for (var i = 0; i &lt; rows.length; i++) { if (i &lt; from || i &gt; to) rows[i].style.display = 'none'; else rows[i].style.display = ''; } } this.showPage = function(pageNumber) { if (! this.inited) { alert("not inited"); return; } var oldPageAnchor = document.getElementById('pg'+this.currentPage); oldPageAnchor.className = 'pg-normal'; this.currentPage = pageNumber; var newPageAnchor = document.getElementById('pg'+this.currentPage); newPageAnchor.className = 'pg-selected'; var from = (pageNumber - 1) * itemsPerPage; var to = from + itemsPerPage - 1; this.showRecords(from, to); } this.prev = function() { if (this.currentPage &gt; 1) this.showPage(this.currentPage - 1); } this.next = function() { if (this.currentPage &lt; this.pages) { this.showPage(this.currentPage + 1); } } this.init = function() { var rows = $('.' + class_name); var records = (rows.length); this.pages = Math.ceil(records / itemsPerPage); this.inited = true; } this.showPageNav = function(pagerName, positionId) { if (! this.inited) { alert("not inited"); return; } </code></pre> <p>and my problem is here:</p> <pre><code> var element = document.getElementById(positionId); var pagerHtml = '&lt;span onClick="' + pagerName + '.prev();" class="pg-normal"&gt; &amp;#171 Prev &lt;/span&gt; | '; for (var page = 1; page &lt;= this.pages; page++) pagerHtml += '&lt;span id="pg' + page + '" class="pg-normal" onClick="' + pagerName + '.showPage(' + page + ');"&gt;' + page + '&lt;/span&gt; | '; pagerHtml += '&lt;span onClick="'+pagerName+'.next();" class="pg-normal"&gt; Next &amp;#187;&lt;/span&gt;'; element.innerHTML = pagerHtml; } } }); </code></pre> <p>if you wanna look at the demo please follow the link bellow <a href="http://jsfiddle.net/J3Qnx/11/" rel="nofollow">http://jsfiddle.net/J3Qnx/11/</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. 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