Ohhh! During I wrote the code firegnom posted another implementation. Nevertheless better two working versions as no one.
I made small demo which demonstrate how the behavior with links in the pager can be implemented. I made the code so, that it can display the pager either in the form
(if pginput: false
parameter of jqGrid are used) or in the form
In both cases the current page will not displayed in the list. How one can see I inserted the underlined style for the links. If you don't like it you should remove
td.myPager a { text-decoration:underline !important }
from the demo. The working live demos you can see here and here.
The corresponding JavaScript code is full inside of loadComplete
event handler:
loadComplete: function() {
var i, myPageRefresh = function(e) {
var newPage = $(e.target).text();
grid.trigger("reloadGrid",[{page:newPage}]);
e.preventDefault();
};
$(grid[0].p.pager + '_center td.myPager').remove();
var pagerPrevTD = $('<td>', { class: "myPager"}), prevPagesIncluded = 0,
pagerNextTD = $('<td>', { class: "myPager"}), nextPagesIncluded = 0,
totalStyle = grid[0].p.pginput === false,
startIndex = totalStyle? this.p.page-MAX_PAGERS*2: this.p.page-MAX_PAGERS;
for (i=startIndex; i<=this.p.lastpage && (totalStyle? (prevPagesIncluded+nextPagesIncluded<MAX_PAGERS*2):(nextPagesIncluded<MAX_PAGERS)); i++) {
if (i<=0 || i === this.p.page) { continue; }
var link = $('<a>', { href:'#', click:myPageRefresh });
link.text(String(i));
if (i<this.p.page || totalStyle) {
if (prevPagesIncluded>0) { pagerPrevTD.append('<span>, </span>'); }
pagerPrevTD.append(link);
prevPagesIncluded++;
} else {
if (nextPagesIncluded>0 || (totalStyle && prevPagesIncluded>0)) { pagerNextTD.append('<span>, </span>'); }
pagerNextTD.append(link);
nextPagesIncluded++;
}
}
if (prevPagesIncluded > 0) {
$(grid[0].p.pager + '_center td[id^="prev"]').after(pagerPrevTD);
}
if (nextPagesIncluded > 0) {
$(grid[0].p.pager + '_center td[id^="next"]').before(pagerNextTD);
}
}
where grid
and MAX_PAGERS
are defined as
var grid = $("#list"), MAX_PAGERS = 2;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…