add language option to select.js

pull/505/head
Danilo Duarte 4 years ago
parent cb93ce9ddd
commit 3b5da684ea

@ -14,6 +14,9 @@
* } ); * } );
*/ */
var paginateSelectClassName = 'paginate_select';
var paginateTotalClassName = 'paginate_total';
$.fn.dataTableExt.oPagination.listbox = { $.fn.dataTableExt.oPagination.listbox = {
/* /*
* Function: oPagination.listbox.fnInit * Function: oPagination.listbox.fnInit
@ -25,20 +28,29 @@ $.fn.dataTableExt.oPagination.listbox = {
*/ */
"fnInit": function (oSettings, nPaging, fnCallbackDraw) { "fnInit": function (oSettings, nPaging, fnCallbackDraw) {
var nInput = document.createElement('select'); var nInput = document.createElement('select');
var nPage = document.createElement('span'); var nTotal = document.createElement('span');
var nOf = document.createElement('span'); var nInfo = document.createElement('span');
nOf.className = "paginate_of";
nPage.className = "paginate_page"; var language = oSettings.oLanguage.oPaginate;
var info = language.info || 'Page _INPUT_ of _TOTAL_';
nInput.className = paginateSelectClassName;
nTotal.className = paginateTotalClassName;
if (oSettings.sTableId !== '') { if (oSettings.sTableId !== '') {
nPaging.setAttribute('id', oSettings.sTableId + '_paginate'); nPaging.setAttribute('id', oSettings.sTableId + '_paginate');
} }
nInput.style.display = "inline"; nInput.style.display = "inline";
nPage.innerHTML = "Page ";
nPaging.appendChild(nPage); info = info.replace(/_INPUT_/g, '</span>' + nInput.outerHTML + '<span>');
nPaging.appendChild(nInput); info = info.replace(/_TOTAL_/g, '</span>' + nTotal.outerHTML);
nPaging.appendChild(nOf); nInfo.innerHTML = '<span>' + info;
$(nInput).change(function (e) { // Set DataTables page property and redraw the grid on listbox change event.
window.scroll(0,0); //scroll to top of page $(nInfo).children().each(function (i, n) {
nPaging.appendChild(n);
});
$(nPaging).find('.' + paginateSelectClassName).change(function (e) { // Set DataTables page property and redraw the grid on listbox change event.
if (this.value === "" || this.value.match(/[^0-9]/)) { /* Nothing entered or non-numeric character */ if (this.value === "" || this.value.match(/[^0-9]/)) { /* Nothing entered or non-numeric character */
return; return;
} }
@ -73,25 +85,22 @@ $.fn.dataTableExt.oPagination.listbox = {
var iPages = Math.ceil((oSettings.fnRecordsDisplay()) / oSettings._iDisplayLength); var iPages = Math.ceil((oSettings.fnRecordsDisplay()) / oSettings._iDisplayLength);
var iCurrentPage = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength) + 1; /* Loop over each instance of the pager */ var iCurrentPage = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength) + 1; /* Loop over each instance of the pager */
var an = oSettings.aanFeatures.p; var an = oSettings.aanFeatures.p;
for (var i = 0, iLen = an.length; i < iLen; i++) {
var spans = an[i].getElementsByTagName('span'); var elSel = $(an).find('.' + paginateSelectClassName);
var inputs = an[i].getElementsByTagName('select');
var elSel = inputs[0]; if(elSel.children('option').length != iPages) {
if(elSel.options.length != iPages) { for (var j = 0; j < iPages; j++) { //add the pages
elSel.options.length = 0; //clear the listbox contents var oOption = document.createElement('option');
for (var j = 0; j < iPages; j++) { //add the pages oOption.text = j + 1;
var oOption = document.createElement('option'); oOption.value = j + 1;
oOption.text = j + 1;
oOption.value = j + 1; elSel.append(oOption);
try {
elSel.add(oOption, null); // standards compliant; doesn't work in IE
} catch (ex) {
elSel.add(oOption); // IE only
}
}
spans[1].innerHTML = "&nbsp;of&nbsp;" + iPages;
} }
elSel.value = iCurrentPage;
} }
elSel.val(iCurrentPage);
$(an).find('.' + paginateTotalClassName).html(iPages);
} }
}; };

Loading…
Cancel
Save