分页计数器不计数或更新

时间:2013-08-01 15:59:14

标签: jquery

下面是我的分页代码,我试图自己添加一个寻呼机,但它总是显示1条记录,当它为零时它也没有正确计算它们并且当结果缩小时它不会更新(通过我的搜索代码它只调用了paginate函数(我试过了至少哈哈)

我也想知道不是在之前或之后插入寻呼机,我可以将它插入占位符div吗?

function paginate(table) {
    $(table).each(function () {
        var currentPage = 0;
        var numPerPage = 30;
        var pageCount = 0;
        var pageNo = 0;

        var $table = $(this);
        $table.bind('repaginate', function () {
            $table.children('tbody').children('tr:not(.exclude)').hide().slice(currentPage * numPerPage, (currentPage + 1) * numPerPage).show();
        });
        $table.trigger('repaginate');
        var numRows = $table.children('tbody').children('tr:not(.exclude)').length;

        var numPages = Math.ceil(numRows / numPerPage);
        var $pager = $('<div id="pager" class="pager"></div>');
        for (var page = 0; page < numPages; page++) {
            $('<span class="page-number"></span>').text(page + 1).bind('click', {
                newPage: page
            }, function (event) {
                currentPage = event.data['newPage'];
                $table.trigger('repaginate');
                $(this).addClass('active').siblings().removeClass('active');
            }).appendTo($pager).addClass('clickable');
        }
        // Clear the old pager first
        $('#pager').remove();
        $pager.insertBefore($table).find('span.page-number:first').addClass('active');
        //Clear the old counter
        $('#counter').remove();
        if (numRows < numPerPage) {
            pageCount = numRows;
            pageNo = 1;
        }
        else {
            pageCount = currentPage + numPerPage;
            pageNo = (numPerPage * currentPage) + 1;
        }
        var $counter = $('<div id="counter">Showing ' + pageNo + ' to ' + pageCount + ' of ' + numRows + ' Records</div>');
        $counter.insertBefore($pager);
    });
}

function searchPagingTable(inputVal, tablename, fixedsearch, exclude) {
    var table = $(tablename);
    table.find('tr:not(.header)').each(function (index, row) {
        var allCells = $(row).find('td');
        if (allCells.length > 0) {
            var found = false;
            allCells.each(function (index, td) {
                if (fixedsearch == 1 || exclude.length > 0) {
                    var regExp = new RegExp("\\b" + inputVal + "\\b");
                }
                else {
                    var regExp = new RegExp(inputVal, 'i');
                }
                if (regExp.test($(td).text())) {
                    found = true;
                    return false;
                }
            });
            if (exclude.length > 0) {
                if (found == true) $(row).hide().addClass('exclude'); else $(row).show().removeClass('exclude');
            }
            else {
                if (found == true) $(row).show().removeClass('exclude'); else $(row).hide().addClass('exclude');
            }
        }
    });
    paginate();
}

1 个答案:

答案 0 :(得分:0)

我建议你使用http://datatables.net/ 它确实希望您通过查看代码来创建