table.js 5.49 KB
var currentPage = 1;
var pageCount = 2;
var data=[];
for(var i=0;i<14;i++){
	data[i]=i;
}
genarateOrderMsgTable(data);
genaratePaginationDiv(pageCount);
function genarateOrderMsgTable(orderMsgList) {
    var innerHTML = "";
    for (var i = 0; i < orderMsgList.length; i ++) {
        innerHTML += "<tr><td style='text-align: center;'>" + data[1] + "</td>";
		innerHTML += "<td style='text-align: center;'>" + data[2] + "</td>";
		innerHTML += "<td style='text-align: center;'>" + data[3] + "</td>";
		innerHTML += "<td style='text-align: center;'>" + data[4] + "</td>";
		innerHTML += "<td style='text-align: center;'><button class='btn btn-danger btn-mini'>delete</button>&nbsp;&nbsp;&nbsp;&nbsp;<button class='btn btn-inverse btn-mini'>edit</button></td></tr>";
    }
    document.getElementById('div-table-Order-error').getElementsByTagName("tbody")[0].innerHTML = innerHTML;
}

/**
 * 生成换页组件
 * @param pageCount
 * @param currentPage
 */
function genaratePaginationDiv(pageCount) {
    var innerHTML = genaratePagination(pageCount, currentPage, "aHref");
    document.getElementById('div_page').innerHTML = innerHTML;
}

/**
 * 生成换页组件
 *
 * @param page 总的页数
 * @param currentPage 当前页序号
 * @returns {string} 生成换页组件的innerHTML
 */
function genaratePagination(pageCount, currentPage, functionName) {
    var isNeedLeft3Point = false;
    var isNeedRightPoint = false;

    var left;
    var right;

    var innerHTML = "";
    innerHTML += "<div class='dataTables_paginate fg-buttonset ui-buttonset fg-buttonset-multi ui-buttonset-multi paging_full_numbers'>";

    if(pageCount <= 10) {
        left = 0;
        right = pageCount;
    } else {
        if (currentPage < 5) {
            left = 0;
            right =10;
            isNeedRightPoint = true;
        } else if (currentPage >= pageCount  - 5) {
            left = pageCount - 10;
            right = pageCount;
            isNeedLeft3Point = true;
        } else {
            left = currentPage - 4;
            right = Number(currentPage) + Number(6);
            isNeedRightPoint = true;
            isNeedLeft3Point = true;
        }
    }

    //生成向前翻页按钮
    if(currentPage == 0) {
    	innerHTML +="<a tabindex='0' class='first ui-corner-tl ui-corner-bl fg-button ui-button ui-state-default' id='div-table-Order-error_first'>First</a>";
    	innerHTML +="<a tabindex='0' class='previous fg-button ui-button ui-state-default' id='div-table-Order-error_previous'>Previous</a>";
       
    } else {
    	
    	innerHTML +="<a href=\"javascript:" + functionName + "(\'"+ "FIRST_PAGE" +"\')\" tabindex='0' class='first ui-corner-tl ui-corner-bl fg-button ui-button ui-state-default' id='div-table-Order-error_first'>First</a>";
    	innerHTML +="<a href=\"javascript:" + functionName + "(\'"+ "LEFT_PAGE" +"\')\" tabindex='0' class='previous fg-button ui-button ui-state-default' id='div-table-Order-error_previous'>Previous</a>";
      
    }
    if(isNeedLeft3Point) {
        innerHTML += "<a class='disabled'>...</a>";
    }

    //生成中间页翻页按钮
    for(var i = left; i < right; i ++) {

        if(i == currentPage) {
            var page = Number(i) + 1;
            innerHTML += "<a href=\"javascript:" + functionName + "(\'"+ i +"\')\">" + page + "</a>";
        } else {
            var page = Number(i) + 1;
            innerHTML += "<a href=\"javascript:" + functionName + "(\'"+ i +"\')\">" + page + "</a></li>";
        }
    }

    //向后翻页按钮翻页按钮
    if (isNeedRightPoint) {
        innerHTML += "<a class='disabled'>...</a>";
    }
    if (currentPage == pageCount - 1) {
    	innerHTML +="<a tabindex='0' class='next fg-button ui-button ui-state-default ui-state-disabled' id='div-table-Order-error_next'>Next</a>";
    	innerHTML +="<a tabindex='0' class='last ui-corner-tr ui-corner-br fg-button ui-button ui-state-default ui-state-disabled' id='div-table-Order-error_last'>Last</a>";
    } else {
    	
    	innerHTML +="<a href=\"javascript:" + functionName + "(\'"+ "RIGHT_PAGE" +"\')\" tabindex='0' class='next fg-button ui-button ui-state-default ui-state-disabled' id='div-table-Order-error_next'>Next</a>";
    	innerHTML +="<a href=\"javascript:" + functionName + "(\'"+ "LAST_PAGE" +"\')\" tabindex='0' class='last ui-corner-tr ui-corner-br fg-button ui-button ui-state-default ui-state-disabled' id='div-table-Order-error_last'>Last</a>";
      
    }

    return innerHTML;
}

/**
 * 换页组件的跳转方法
 */
function aHref(page) {
    switch (page) {
        case "RIGHT_PAGE" :
            currentPage ++;
            break;
        case "LEFT_PAGE" :
            currentPage --;
            break;
        case "FIRST_PAGE" :
            currentPage = 0;
            break;
        case "LAST_PAGE" :
            currentPage = pageCount - 1;
            break;
        default :
            currentPage = page;
    }
}

$(function () {
    $('.tree li:has(ul)').addClass('parent_li').find(' > span').attr('title', 'Collapse this branch');
    $('.tree li.parent_li > span').on('click', function (e) {
        var children = $(this).parent('li.parent_li').find(' > ul > li');
        if (children.is(":visible")) {
            children.hide('fast');
            $(this).attr('title', 'Expand this branch').find(' > i').addClass('icon-plus-sign').removeClass('icon-minus-sign');
        } else {
            children.show('fast');
            $(this).attr('title', 'Collapse this branch').find(' > i').addClass('icon-minus-sign').removeClass('icon-plus-sign');
        }
        e.stopPropagation();
    });
});