Add a range to a jQuery pagination?

Discussion in 'jQuery' started by 123GoToAndPlay, Mar 18, 2010.

  1. #1
    Hello,

    i followed the pagination from http://www.packtpub.com/article/jquery-table-manipulation-part1

    and now i like to add a range
    So instead of [1][2][3][4][5][6][7]

    i like something [1][2][3][>][last]

    the .js code i am using right now is

    
    function paginateIt() {
    $("#pagination-ajax").remove();
      $('table#overviewJobs').each(function() {
    
        var currentPage = 0;
        var numPerPage = 7;
        var $table = $(this);
    
        $table.bind('repaginate', function() {
    
            $table.find('tbody tr').show()
    
                    .slice(0,currentPage * numPerPage)
                    .hide()
                    .end()
    
                    .slice((currentPage + 1) * numPerPage)
                    .hide()
                    .end();
    
              });
    
        var numRows = $table.find('tbody tr').length;
        //alert("Num of rows "+numRows);
        var numPages = Math.ceil(numRows / numPerPage);
    
        var $pager = $('<div id="pagination-ajax"></div>');
    
        if(numRows > numPerPage) {
            for (var page = 0; page < numPages; page++) {
              $('<span class="page-number">' + (page + 1) + '</span>')
               .bind('click', {'newPage': page}, function(event) {
                 currentPage = event.data['newPage'];
                 //numPerPage = 7;
                 $table.trigger('repaginate');
                 $(this).addClass('active').siblings().removeClass('active');
               })
               .appendTo($pager).addClass('clickable');
            }
            $pager.find('span.page-number:first').addClass('active');
            $pager.insertAfter($('#pagination-divider'));
        } //end if numRows
        //
        //$('#pagination').html(navigation_html);
        $table.trigger('repaginate');
    
      });
    };
    
    
    Code (markup):
    Any help?/
     
    123GoToAndPlay, Mar 18, 2010 IP