Update input.js

Added disabling of the First/Previous/Next/Last buttons.
Made it so entering 0 won't break the table.
Move input styles into a class instead.
pull/92/head
Anderezekial 10 years ago
parent b4975f94cb
commit 4fd76ca82c

@ -39,6 +39,7 @@ $.fn.dataTableExt.oPagination.input = {
nLast.className = "paginate_button last"; nLast.className = "paginate_button last";
nOf.className = "paginate_of"; nOf.className = "paginate_of";
nPage.className = "paginate_page"; nPage.className = "paginate_page";
nInput.className = "paginate_input";
if ( oSettings.sTableId !== '' ) if ( oSettings.sTableId !== '' )
{ {
@ -50,8 +51,6 @@ $.fn.dataTableExt.oPagination.input = {
} }
nInput.type = "text"; nInput.type = "text";
nInput.style.width = "15px";
nInput.style.display = "inline";
nPage.innerHTML = "Page "; nPage.innerHTML = "Page ";
nPaging.appendChild( nFirst ); nPaging.appendChild( nFirst );
@ -65,28 +64,58 @@ $.fn.dataTableExt.oPagination.input = {
$(nFirst).click( function () { $(nFirst).click( function () {
oSettings.oApi._fnPageChange( oSettings, "first" ); oSettings.oApi._fnPageChange( oSettings, "first" );
fnCallbackDraw( oSettings ); fnCallbackDraw( oSettings );
$(nFirst).addClass('disabled');
$(nPrevious).addClass('disabled');
$(nNext).removeClass('disabled');
$(nLast).removeClass('disabled');
} ); } );
$(nPrevious).click( function() { $(nPrevious).click( function() {
oSettings.oApi._fnPageChange( oSettings, "previous" ); oSettings.oApi._fnPageChange( oSettings, "previous" );
fnCallbackDraw( oSettings ); fnCallbackDraw( oSettings );
if ($(nInput).val() == 2)
{
$(nFirst).addClass('disabled');
$(nPrevious).addClass('disabled');
}
else
{
$(nNext).removeClass('disabled');
$(nLast).removeClass('disabled');
}
} ); } );
$(nNext).click( function() { $(nNext).click( function() {
oSettings.oApi._fnPageChange( oSettings, "next" ); oSettings.oApi._fnPageChange( oSettings, "next" );
fnCallbackDraw( oSettings ); fnCallbackDraw( oSettings );
if ($(nInput).val() == (Math.ceil((oSettings.fnRecordsDisplay() - 1) / oSettings._iDisplayLength) - 1))
{
$(nNext).addClass('disabled');
$(nLast).addClass('disabled');
}
else
{
$(nFirst).removeClass('disabled');
$(nPrevious).removeClass('disabled');
}
} ); } );
$(nLast).click( function() { $(nLast).click( function() {
oSettings.oApi._fnPageChange( oSettings, "last" ); oSettings.oApi._fnPageChange( oSettings, "last" );
fnCallbackDraw( oSettings ); fnCallbackDraw( oSettings );
$(nFirst).removeClass('disabled');
$(nPrevious).removeClass('disabled');
$(nNext).addClass('disabled');
$(nLast).addClass('disabled');
} ); } );
$(nInput).keyup( function (e) { $(nInput).keyup( function (e) {
// 38 = up arrow, 39 = right arrow
if ( e.which == 38 || e.which == 39 ) if ( e.which == 38 || e.which == 39 )
{ {
this.value++; this.value++;
} }
// 37 = left arrow, 40 = down arrow
else if ( (e.which == 37 || e.which == 40) && this.value > 1 ) else if ( (e.which == 37 || e.which == 40) && this.value > 1 )
{ {
this.value--; this.value--;
@ -99,13 +128,32 @@ $.fn.dataTableExt.oPagination.input = {
} }
var iNewStart = oSettings._iDisplayLength * (this.value - 1); var iNewStart = oSettings._iDisplayLength * (this.value - 1);
var iEndPosition = (Math.ceil((oSettings.fnRecordsDisplay() - 1) / oSettings._iDisplayLength) - 1) * oSettings._iDisplayLength;
if (iNewStart < 0)
{
iNewStart = 0;
}
if (iNewStart > oSettings.fnRecordsDisplay()) if (iNewStart > oSettings.fnRecordsDisplay())
{ {
/* Display overrun */ iNewStart = iEndPosition;
oSettings._iDisplayStart = (Math.ceil((oSettings.fnRecordsDisplay()-1) / }
oSettings._iDisplayLength)-1) * oSettings._iDisplayLength;
fnCallbackDraw( oSettings ); if (iNewStart == 0)
return; {
$(nFirst).addClass('disabled');
$(nPrevious).addClass('disabled');
}
else if (iNewStart == iEndPosition)
{
$(nNext).addClass('disabled');
$(nLast).addClass('disabled');
}
else
{
$(nFirst).removeClass('disabled');
$(nPrevious).removeClass('disabled');
$(nNext).removeClass('disabled');
$(nLast).removeClass('disabled');
} }
oSettings._iDisplayStart = iNewStart; oSettings._iDisplayStart = iNewStart;

Loading…
Cancel
Save