分页错误显示下一页

时间:2015-07-21 12:04:03

标签: javascript jquery pagination

JIRA(http://d.pr/i/18cjv)中的自定义分页,每页有20条记录限制大小,当有20条记录中的20条时,显示下一页空白而没有记录(http://d.pr/i/19Dyh)。

此页面不应出现,直到它将是21记录(也适用于所有下一页)。

JS:

var 页面 - 当前页面

var 总计 - 所有记录

var 记录 - 页面上的当前记录

renderTable(页面) - 显示记录字段取决于页码

function renderPaging(parsedFieldsResult) {

    var firstResult = (page - 1) * 20;
            if (firstResult == 0) {
                firstResult = 1;
            }

    var lastResult = page * 20;
            if (lastResult > records) {
                lastResult = records;
            }

// summary with count of pages
            var pagingContent = '';
            pagingContent += '<div class="classname-pagination-summary">';
            pagingContent += '<strong class="first" id="table-first-page-bottom">';
            pagingContent += firstResult;
            pagingContent += '</strong>';
            pagingContent += ' &ndash; ';
            pagingContent += '<strong class="last" id="table-last-page-bottom">';
            pagingContent += lastResult;
            pagingContent += '</strong>';
            pagingContent += ' of ';
            pagingContent += '<strong class="total" id="table-pages-total-bottom">';
            pagingContent += records;
            pagingContent += '</strong>';
            pagingContent += '</div>';
            pagingContent += '<ol class="aui-nav aui-nav-pagination">';

// previous icon
            pagingContent += '<li class="aui-nav-previous">';
            pagingContent += '<a href="#" class="icon icon-previous" ';

            if (page > 1 && total > 1) {
                pagingContent += ' onclick="renderTable(';
                pagingContent += (page - 1);
                pagingContent += ')" ';
            }

            pagingContent += '>';
            pagingContent += '<span>Back</span>';
            pagingContent += '</a>';
            pagingContent += '</li>';


            var firstPage = page - 2;
            var lastPage = page + 2;

            if (firstPage < 1) {
                lastPage += (page - firstPage);
                firstPage = 1;
            }

            if (lastPage > total) {
                firstPage -= (lastPage - total);
                lastPage = total;
            }

            if (firstPage < 1) {
                firstPage = 1;
            }

// make current page selected (somewhere here mistake)
            for (var pageItem = firstPage; pageItem <= lastPage; pageItem++) {
                if (pageItem === page) {
                    pagingContent += '<li class="aui-nav-selected">';
                    pagingContent += pageItem;
                    pagingContent += '</li>';
                } else {
                    pagingContent += '<li><a class="page" href="#" ';
                    pagingContent += ' onclick="renderTable(';
                    pagingContent += pageItem;
                    pagingContent += ')" ';
                    pagingContent += ' >';
                    pagingContent += pageItem;
                    pagingContent += '</a></li>';
                }
            }
// next icon
            pagingContent += '<li class="aui-nav-next">';
            pagingContent += '<a href="#" class="icon icon-next" ';

            if (page < total && records > lastResult) {
                pagingContent += ' onclick="renderTable(';
                pagingContent += (page + 1);
                pagingContent += ')" ';
            }

            pagingContent += '>';
            pagingContent += '<span>Next</span>';
            pagingContent += '</a>';
            pagingContent += '</li>';
            pagingContent += '</ol>';

            jQuery("#pagination-id").html(pagingContent);           
  }

(这不是我自己的代码,我认为它构造得很糟糕)

应该添加什么条件?

我会很高兴得到任何帮助。谢谢!

0 个答案:

没有答案