Merge pull request #392 from fred104/master

Use template to generate pagination info
pull/397/head
Allan Jardine 6 years ago committed by GitHub
commit 47eb88cc28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -54,9 +54,9 @@
var lastClassName = 'last'; var lastClassName = 'last';
var paginateClassName = 'paginate'; var paginateClassName = 'paginate';
var paginateOfClassName = 'paginate_of';
var paginatePageClassName = 'paginate_page'; var paginatePageClassName = 'paginate_page';
var paginateInputClassName = 'paginate_input'; var paginateInputClassName = 'paginate_input';
var paginateTotalClassName = 'paginate_total';
$.fn.dataTableExt.oPagination.input = { $.fn.dataTableExt.oPagination.input = {
'fnInit': function (oSettings, nPaging, fnCallbackDraw) { 'fnInit': function (oSettings, nPaging, fnCallbackDraw) {
@ -65,11 +65,12 @@
var nNext = document.createElement('span'); var nNext = document.createElement('span');
var nLast = document.createElement('span'); var nLast = document.createElement('span');
var nInput = document.createElement('input'); var nInput = document.createElement('input');
var nPage = document.createElement('span'); var nTotal = document.createElement('span');
var nOf = document.createElement('span'); var nInfo = document.createElement('span');
var language = oSettings.oLanguage.oPaginate; var language = oSettings.oLanguage.oPaginate;
var classes = oSettings.oClasses; var classes = oSettings.oClasses;
var info = language.info || 'Page _INPUT_ of _TOTAL_';
nFirst.innerHTML = language.sFirst; nFirst.innerHTML = language.sFirst;
nPrevious.innerHTML = language.sPrevious; nPrevious.innerHTML = language.sPrevious;
@ -81,9 +82,8 @@
nNext.className = nextClassName + ' ' + classes.sPageButton; nNext.className = nextClassName + ' ' + classes.sPageButton;
nLast.className = lastClassName + ' ' + classes.sPageButton; nLast.className = lastClassName + ' ' + classes.sPageButton;
nOf.className = paginateOfClassName;
nPage.className = paginatePageClassName;
nInput.className = paginateInputClassName; nInput.className = paginateInputClassName;
nTotal.className = paginateTotalClassName;
if (oSettings.sTableId !== '') { if (oSettings.sTableId !== '') {
nPaging.setAttribute('id', oSettings.sTableId + '_' + paginateClassName); nPaging.setAttribute('id', oSettings.sTableId + '_' + paginateClassName);
@ -94,13 +94,16 @@
} }
nInput.type = 'text'; nInput.type = 'text';
nPage.innerHTML = 'Page ';
info = info.replace(/_INPUT_/g, '</span>' + nInput.outerHTML + '<span>');
info = info.replace(/_TOTAL_/g, '</span>' + nTotal.outerHTML + '<span>');
nInfo.innerHTML = '<span>' + info + '</span>';
nPaging.appendChild(nFirst); nPaging.appendChild(nFirst);
nPaging.appendChild(nPrevious); nPaging.appendChild(nPrevious);
nPaging.appendChild(nPage); $(nInfo).children().each(function (i, n) {
nPaging.appendChild(nInput); nPaging.appendChild(n);
nPaging.appendChild(nOf); });
nPaging.appendChild(nNext); nPaging.appendChild(nNext);
nPaging.appendChild(nLast); nPaging.appendChild(nLast);
@ -136,7 +139,7 @@
} }
}); });
$(nInput).keyup(function (e) { $(nPaging).find('.' + paginateInputClassName).keyup(function (e) {
// 38 = up arrow, 39 = right arrow // 38 = up arrow, 39 = right arrow
if (e.which === 38 || e.which === 39) { if (e.which === 38 || e.which === 39) {
this.value++; this.value++;
@ -215,10 +218,10 @@
.addClass(disableClasses[lastClassName]); .addClass(disableClasses[lastClassName]);
// Paginate of N pages text // Paginate of N pages text
$(an).children('.' + paginateOfClassName).html(' of ' + iPages); $(an).find('.' + paginateTotalClassName).html(iPages);
// Current page numer input value // Current page number input value
$(an).children('.' + paginateInputClassName).val(iCurrentPage); $(an).find('.' + paginateInputClassName).val(iCurrentPage);
} }
}; };
})(jQuery); })(jQuery);

Loading…
Cancel
Save