0

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

我也想知道,而不是将寻呼机插入之前或之后,我可以让它插入占位符 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();
}
4

1 回答 1

0

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

于 2013-08-01T16:06:05.833 回答