我需要帮助来修改打击代码,我在jqgrid分页中需要什么:
第一视图: 第1页,共106页(106项)< [1] 2 3 4 5 6 7 ... 104 105 106>
第二种观点: 第7页,共106页(106项)< 1 2 3 ... 6 [7] 8 9 ... 104 105 106>
第三种观点: 第101页,共106页(106项)< 1 2 3 ... 100 [101] 102 103 104 105 106>
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;}
答案 0 :(得分:0)
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);
}
}