pagination.js

阅读更多
function appendPaginationButton(pageInfo, actionUrl, pageSize, column, way) {
    var totalPage = pageInfo.totalPage;
    var allRow = pageInfo.allRow;
    var currentPage = pageInfo.currentPage;
    var offset = (currentPage - 1) * pageSize;
    var currentListSize = pageInfo.currentListSize;
    var buttonListLength = 8;
    var pagination = $("#pagination");
    pagination.empty();
    if (allRow < pageSize ) {
        pagination.append("
" + offset + "-" + allRow + " of " + allRow + "
");
    } else {
    pagination.append("
" + (offset +1) + "-" + (offset + currentListSize) + " of " + allRow + "
");
    }

    pagination.append("
");
    $("#per_page").change(function(){
    var size = $("#per_page").val();
    pageSize = size;
        getPageBean(actionUrl, 1, pageSize, column, way);
    });
    if (pageSize == "2") {
        $("#per_page option[value='2']").attr("selected", true);
    }
    if (pageSize == "4") {
        $("#per_page option[value='4']").attr("selected", true);
    }
    if (pageSize == "6") {
        $("#per_page option[value='6']").attr("selected", true);
    }
    pagination.append("");
    pagination.append("");
    if (totalPage <= buttonListLength) {
        for (var k = 1; k <= totalPage; k++) {
            if ( k == currentPage) {
                pagination.append(""+k+"");
            } else {
                pagination.append(""+k+"");
            }
        }
    } else if (totalPage > buttonListLength && currentPage <= buttonListLength/2 ) {
         for (var k = 1; k <= buttonListLength; k++) {
            if ( k == currentPage) {
                pagination.append(""+k+"");
            } else {
                pagination.append(""+k+"");
            }
         }
    } else if (totalPage >= buttonListLength && currentPage > buttonListLength/2 && currentPage + buttonListLength/2 <=  totalPage) {
        for (var k = (currentPage - buttonListLength/2 + 1); k <= (currentPage +  buttonListLength/2); k++) {
            if ( k == currentPage) {
                pagination.append(""+k+"");
            } else {
                pagination.append(""+k+"");
            }
         }
    } else if (totalPage >= buttonListLength && (currentPage + buttonListLength/2 > totalPage) ) {
        for (var k = (totalPage - buttonListLength + 1); k <= totalPage; k++) {
            if ( k == currentPage) {
                pagination.append(""+k+"");
            } else {
                pagination.append(""+k+"");
            }
         }
    }

    if (currentPage + 1 > totalPage) {
        pagination.append("");
    } else {
        pagination.append("");
    }
    pagination.append("");
    pagination.append("
  

你可能感兴趣的:(go)