table.js
5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
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> <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();
});
});