繁体   English   中英

jqgrid数字分页

[英]jqgrid numeric paging

我需要帮助来修改打击代码,在jqgrid分页中需要什么:

第一视图:第1页,共106页(106个项目)<[1] 2 3 4 5 6 7…104 105106>

第二种视图:第7页,共106页(106个项目)<1 2 3…6 [7] 8 9…104 105 106>

第三张视图:第101页,共106页(106个项目)<1 2 3…100 [101] 102103104105106>

function BuildGroupedPagination(current_page, total_pages, gridId) {
var strPages = "";
var intMaxPages = 0;
var intMinPages = 0;
var intPaginI = 0;
var li;
var link;

var myPageRefresh = function (e) {
    var newPage = $(e.target).text();
    $("#" + gridId).trigger("reloadGrid", [{ page: newPage }]);
    e.preventDefault();
};

//var custom_pager = $('<ul>', { 'class': 'pageMiddle' });
var custom_pager = $('<ul>', { 'id': 'custom_pager', 'class': 'clearfix' });

if (total_pages > 10) {
    if (total_pages > 3) {
        intMaxPages = 3;
    }
    else {
        intMaxPages = total_pages;
    }

    for (intPaginI = 1; intPaginI <= intMaxPages; intPaginI++) {
        link = jQuery('<a>', { href: '#', click: myPageRefresh });
        link.text(String(intPaginI));

        if (intPaginI == current_page) {
            current = 'current_page';
        }
        else {
            current = '';
        }

        li = jQuery('<li>', { id: current }).append(link);

        jQuery(custom_pager).append(li);
    }

    if (total_pages > 3) {
        if ((current_page > 1) && (current_page < total_pages)) {
            if (current_page > 5) {
                li = jQuery('<li>', { 'class': 'pageMiddle' }).append('...');
                jQuery(custom_pager).append(li);
            }

            if (current_page > 4) {
                intMinPages = current_page;
            }
            else {
                intMinPages = 5;
            }

            if (current_page < total_pages - 4) {
                intMaxPages = current_page;
            }
            else {
                intMaxPages = total_pages - 4;
            }

            for (intPaginI = intMinPages - 1 ; intPaginI <= intMaxPages + 1; intPaginI++) {
                link = jQuery('<a>', { href: '#', click: myPageRefresh });
                link.text(String(intPaginI));

                if (intPaginI == current_page) {
                    current = 'current_page';
                }
                else {
                    current = '';
                }

                li = jQuery('<li>', { id: current }).append(link);

                jQuery(custom_pager).append(li);
            }

            if (current_page < total_pages - 4) {
                li = jQuery('<li>', { 'class': 'pageMiddle' }).append('...');
                jQuery(custom_pager).append(li);
            }
        }
        else {
            li = jQuery('<li>', { 'class': 'pageMiddle' }).append('...');
            jQuery(custom_pager).append(li);
        }

        for (intPaginI = total_pages - 2; intPaginI <= total_pages; intPaginI++) {
            link = jQuery('<a>', { href: '#', click: myPageRefresh });
            link.text(String(intPaginI));

            if (intPaginI == current_page) {
                current = 'current_page';
            }
            else {
                current = '';
            }

            li = jQuery('<li>', { id: current }).append(link);

            jQuery(custom_pager).append(li);
        }
    }
}
else {
    for (intPaginI = 1; intPaginI <= total_pages; intPaginI++) {
        link = jQuery('<a>', { href: '#', click: myPageRefresh });
        link.text(String(intPaginI));

        if (intPaginI == current_page) {
            current = 'current_page';
        }
        else {
            current = '';
        }

        li = jQuery('<li>', { id: current }).append(link);

        jQuery(custom_pager).append(li);
    }
}
return custom_pager;}

Blow是我的问题的代码,如果我对此逻辑代码有任何错误或更短的错误之处,请更正

if (total_pages > 10) {

    if (current_page < 7) {
        intMaxPages = 7;
    }
    else {
        intMaxPages = 3;
    }

    for (intPaginI = 1; intPaginI <= intMaxPages; intPaginI++) {
        link = jQuery('<a>', { href: '#', click: myPageRefresh });
        link.text(String(intPaginI));

        if (intPaginI == current_page) {
            current = 'current_page';
        }
        else {
            current = '';
        }

        li = jQuery('<li>', { id: current }).append(link);

        jQuery(custom_pager).append(li);
    }

    li = jQuery('<li>', { 'class': 'pageMiddle' }).append('...');
    jQuery(custom_pager).append(li);

    if (current_page > 6 && current_page < total_pages - 6) {
        for (intPaginI = current_page - 1 ; intPaginI <= current_page + 2; intPaginI++) {
            link = jQuery('<a>', { href: '#', click: myPageRefresh });
            link.text(String(intPaginI));

            if (intPaginI == current_page) {
                current = 'current_page';
            }
            else {
                current = '';
            }

            li = jQuery('<li>', { id: current }).append(link);

            jQuery(custom_pager).append(li);
        }

        li = jQuery('<li>', { 'class': 'pageMiddle' }).append('...');
        jQuery(custom_pager).append(li);
    }
    if (current_page >= total_pages - 6) {
        intMaxPages = total_pages - 6;
    }
    else {
        intMaxPages = total_pages - 2;
    }

    for (intPaginI = intMaxPages; intPaginI <= total_pages; intPaginI++) {
        link = jQuery('<a>', { href: '#', click: myPageRefresh });
        link.text(String(intPaginI))

        if (intPaginI == current_page) {
            current = 'current_page';
        }
        else {
            current = '';
        }

        li = jQuery('<li>', { id: current }).append(link);
        jQuery(custom_pager).append(li);
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM