FIXED checking limits

pull/243/head
Frank van Os 9 years ago
parent 079321f274
commit 90ec7405cd

@ -5,12 +5,9 @@
* *
* 'maxNormalPages' is used for the maximum pages in normal mode * 'maxNormalPages' is used for the maximum pages in normal mode
* 'maxSelectPages' is used for the selectbox mode * 'maxSelectPages' is used for the selectbox mode
* 'maxInputPages' is used for the input mode,
* 'bootstrapTooltip' is used to display max input value for the input mode with bootstrap tooltip plugin
* *
* @name Dynamic input,select or basic navigation * @name Dynamic input,select list
* * @summary Show a `dt-tag select` `dt-tag input` list of pages the user can pick from.
* @summary Show a `dt-tag select`,`dt-tag input` or basic navigation the user can use to navigate through the tables.
* @author Frank van Os * @author Frank van Os
* *
* @example * @example
@ -23,7 +20,6 @@
$.fn.dataTableExt.oPagination.dynamic_pagination = { $.fn.dataTableExt.oPagination.dynamic_pagination = {
'maxNormalPages': 10, 'maxNormalPages': 10,
'maxSelectPages': 20, 'maxSelectPages': 20,
'maxInputPages': 50,
'bootstrapTooltip': false, 'bootstrapTooltip': false,
'fnClickHandler': function(e) { 'fnClickHandler': function(e) {
var fnCallbackDraw = e.data.fnCallbackDraw, var fnCallbackDraw = e.data.fnCallbackDraw,
@ -84,18 +80,14 @@ $.fn.dataTableExt.oPagination.dynamic_pagination = {
function updatePage(element){ function updatePage(element){
if (element.val() === '' || element.val().match(/[^0-9]/)) { if (element.val() === '' || element.val().match(/[^0-9]/)) {
/* Nothing entered or non-numeric character */ /* Nothing entered or non-numeric character */
element.val() = element.val().replace(/[^\d]/g, ''); // don't even allow anything but digits
return; return;
} }
var iNewStart = oSettings._iDisplayLength * (element.val() - 1); var iNewStart = oSettings._iDisplayLength * (element.val() - 1);
if (iNewStart < 0) { if (iNewStart > oSettings.fnRecordsDisplay()) { /* Display overrun */
iNewStart = 0; oSettings._iDisplayStart = (Math.ceil((oSettings.fnRecordsDisplay() - 1) / oSettings._iDisplayLength) - 1) * oSettings._iDisplayLength;
} fnCallbackDraw(oSettings);
if (iNewStart >= oSettings.fnRecordsDisplay()) { return;
iNewStart = (Math.ceil((oSettings.fnRecordsDisplay() - 1) / oSettings._iDisplayLength) - 1) * oSettings._iDisplayLength;
} }
oSettings._iDisplayStart = iNewStart; oSettings._iDisplayStart = iNewStart;
fnCallbackDraw(oSettings); fnCallbackDraw(oSettings);
} }
@ -159,7 +151,7 @@ $.fn.dataTableExt.oPagination.dynamic_pagination = {
$(paging).hide(); $(paging).hide();
$(info).hide(); $(info).hide();
if(iPages < that.maxNormalPages){ if(iPages <= that.maxNormalPages){
$(paging).find('select,input').css('display','none'); $(paging).find('select,input').css('display','none');
// Erase // Erase
@ -180,45 +172,44 @@ $.fn.dataTableExt.oPagination.dynamic_pagination = {
$(oNumber).appendTo('#'+oSettings.sTableId+'_pagination_controls'); $(oNumber).appendTo('#'+oSettings.sTableId+'_pagination_controls');
} }
} }
else if(iPages > that.maxSelectPages) { else if(iPages > that.maxNormalPages && iPages <= that.maxSelectPages) {
// Erase // Erase
$('#'+oSettings.sTableId+'_pagination_controls').find('a.paginate_button').remove(); $('#'+oSettings.sTableId+'_pagination_controls').find('a.paginate_button').remove();
var inputType = (iPages>that.maxInputPages) ? 'input' : 'select'; var input = $(paging).find('select');
var input = $(paging).find(inputType);
$(input).css('display','inline'); input.css('display','inline');
if(oSettings._iDisplayStart === 0 && oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay()){ if(oSettings._iDisplayStart === 0 && oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay()){
$(input).attr('disabled','disabled').attr('class','form-control disabled'); input.attr('disabled','disabled').attr('class','form-control disabled');
} }
else{ else{
$(input) input
.removeAttr('disabled','disabled') .removeAttr('disabled','disabled')
.attr('class','form-control'); .attr('class','form-control');
} }
if(inputType=='select'){ input.empty();
$(input).empty();
for (var j = 0; j < iPages; j++) { //add the pages for (var j = 0; j < iPages; j++) { //add the pages
$(input).append($('<option>', {value:j+1,text:j+1})); input.append($('<option>', {value:j+1,text:j+1}));
} }
$(input).val(iCurrentPage); input.val(iCurrentPage);
$(paging).find('input').css('display','none'); $(paging).find('input').css('display','none');
} }
else if(inputType=='input'){ else if(iPages > that.maxNormalPages && iPages > that.maxSelectPages){
var input = $(paging).find('input');
input.css('display','inline');
if(that.bootstrapTooltip){ if(that.bootstrapTooltip){
$('.pagination > li > input').attr('data-title','Max. page number: '+iPages).tooltip({ $('.pagination > li > input').attr('data-title','Max. page number: '+iPages).tooltip({
container: '.pagination', container: '.pagination',
placement: 'top' placement: 'top'
}); });
} }
$(input).val(iCurrentPage); input.val(iCurrentPage);
$(paging).find('select').css('display','none'); $(paging).find('select').css('display','none');
} }
}
// When there are pages show pagination block and info block // When there are pages show pagination block and info block
$(paging).show(); $(paging).show();

Loading…
Cancel
Save