Merge pull request #92 from Anderezekial/patch-1

Update input.js
pull/95/head
Allan Jardine 10 years ago
commit db3e9e849f

@ -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,14 +128,33 @@ $.fn.dataTableExt.oPagination.input = {
} }
var iNewStart = oSettings._iDisplayLength * (this.value - 1); var iNewStart = oSettings._iDisplayLength * (this.value - 1);
if ( iNewStart > oSettings.fnRecordsDisplay() ) var iEndPosition = (Math.ceil((oSettings.fnRecordsDisplay() - 1) / oSettings._iDisplayLength) - 1) * oSettings._iDisplayLength;
{ if (iNewStart < 0)
/* Display overrun */ {
oSettings._iDisplayStart = (Math.ceil((oSettings.fnRecordsDisplay()-1) / iNewStart = 0;
oSettings._iDisplayLength)-1) * oSettings._iDisplayLength; }
fnCallbackDraw( oSettings ); if (iNewStart > oSettings.fnRecordsDisplay())
return; {
} iNewStart = iEndPosition;
}
if (iNewStart == 0)
{
$(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;
fnCallbackDraw( oSettings ); fnCallbackDraw( oSettings );

Loading…
Cancel
Save