dd type detection and pagination plug-ins form the DataTables plug-ins pages

pull/2/head
Allan Jardine 13 years ago
parent 2f64691d76
commit 0a50d8c003

@ -0,0 +1,106 @@
/**
* This plug-in provides the mark-up needed for using Twitter Bootstrap's
* pagination styling with DataTables. Note that this plug-in uses the
* fnPagingInfo API plug-in method to obtain paging information.
* @name Twitter Bootstrap
* @author <a href="http://sprymedia.co.uk">Allan Jardine</a>
*
* @example
* $(document).ready(function() {
* $('#example').dataTable( {
* "sPaginationType": "bootstrap"
* } );
* } );
*/
/* API method to get paging information */
$.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings )
{
return {
"iStart": oSettings._iDisplayStart,
"iEnd": oSettings.fnDisplayEnd(),
"iLength": oSettings._iDisplayLength,
"iTotal": oSettings.fnRecordsTotal(),
"iFilteredTotal": oSettings.fnRecordsDisplay(),
"iPage": Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ),
"iTotalPages": Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength )
};
}
/* Bootstrap style pagination control */
$.extend( $.fn.dataTableExt.oPagination, {
"bootstrap": {
"fnInit": function( oSettings, nPaging, fnDraw ) {
var oLang = oSettings.oLanguage.oPaginate;
var fnClickHandler = function ( e ) {
e.preventDefault();
if ( oSettings.oApi._fnPageChange(oSettings, e.data.action) ) {
fnDraw( oSettings );
}
};
$(nPaging).addClass('pagination').append(
'<ul>'+
'<li class="prev disabled"><a href="#">&larr; '+oLang.sPrevious+'</a></li>'+
'<li class="next disabled"><a href="#">'+oLang.sNext+' &rarr; </a></li>'+
'</ul>'
);
var els = $('a', nPaging);
$(els[0]).bind( 'click.DT', { action: "previous" }, fnClickHandler );
$(els[1]).bind( 'click.DT', { action: "next" }, fnClickHandler );
},
"fnUpdate": function ( oSettings, fnDraw ) {
var iListLength = 5;
var oPaging = oSettings.oInstance.fnPagingInfo();
var an = oSettings.aanFeatures.p;
var i, j, sClass, iStart, iEnd, iHalf=Math.floor(iListLength/2);
if ( oPaging.iTotalPages < iListLength) {
iStart = 1;
iEnd = oPaging.iTotalPages;
}
else if ( oPaging.iPage <= iHalf ) {
iStart = 1;
iEnd = iListLength;
} else if ( oPaging.iPage >= (oPaging.iTotalPages-iHalf) ) {
iStart = oPaging.iTotalPages - iListLength + 1;
iEnd = oPaging.iTotalPages;
} else {
iStart = oPaging.iPage - iHalf + 1;
iEnd = iStart + iListLength - 1;
}
for ( i=0, iLen=an.length ; i<iLen ; i++ ) {
// Remove the middle elements
$('li:gt(0)', an[i]).filter(':not(:last)').remove();
// Add the new list items and their event handlers
for ( j=iStart ; j<=iEnd ; j++ ) {
sClass = (j==oPaging.iPage+1) ? 'class="active"' : '';
$('<li '+sClass+'><a href="#">'+j+'</a></li>')
.insertBefore( $('li:last', an[i])[0] )
.bind('click', function (e) {
e.preventDefault();
oSettings._iDisplayStart = (parseInt($('a', this).text(),10)-1) * oPaging.iLength;
fnDraw( oSettings );
} );
}
// Add / remove disabled classes from the static elements
if ( oPaging.iPage === 0 ) {
$('li:first', an[i]).addClass('disabled');
} else {
$('li:first', an[i]).removeClass('disabled');
}
if ( oPaging.iPage === oPaging.iTotalPages-1 || oPaging.iTotalPages === 0 ) {
$('li:last', an[i]).addClass('disabled');
} else {
$('li:last', an[i]).removeClass('disabled');
}
}
}
}
} );

@ -0,0 +1,104 @@
/**
* This pagination plug-in provides pagination controls for DataTables which
* match the style and interaction of the ExtJS library's grid component.
* @name ExtJS style
* @author <a href="http://zachariahtimothy.wordpress.com/">Zach Curtis</a>
*
* @example
* $(document).ready(function() {
* $('#example').dataTable( {
* "sPaginationType": "extStyle"
* } );
* } );
*/
$.fn.dataTableExt.oPagination.extStyle = {
"fnInit": function (oSettings, nPaging, fnCallbackDraw) {
nFirst = $('<span />', { 'class': 'paginate_button first' });
nPrevious = $('<span />', { 'class': 'paginate_button previous' });
nNext = $('<span />', { 'class': 'paginate_button next' });
nLast = $('<span />', { 'class': 'paginate_button last' });
nPageTxt = $("<span />", { text: 'Page' });
nPageNumBox = $('<input />', { type: 'text', val: 1, 'class': 'pageinate_input_box' });
nPageOf = $('<span />', { text: 'of' });
nTotalPages = $('<span />', { text: parseInt(oSettings.aoData.length / oSettings._iDisplayLength, 10) });
$(nPaging)
.append(nFirst)
.append(nPrevious)
.append(nPageTxt)
.append(nPageNumBox)
.append(nPageOf)
.append(nTotalPages)
.append(nNext)
.append(nLast);
nFirst.click(function () {
oSettings.oApi._fnPageChange(oSettings, "first");
fnCallbackDraw(oSettings);
nPageNumBox.val(parseInt(oSettings._iDisplayEnd / oSettings._iDisplayLength, 10));
}).bind('selectstart', function () { return false; });
nPrevious.click(function () {
oSettings.oApi._fnPageChange(oSettings, "previous");
fnCallbackDraw(oSettings);
nPageNumBox.val(parseInt(oSettings._iDisplayEnd / oSettings._iDisplayLength, 10));
}).bind('selectstart', function () { return false; });
nNext.click(function () {
oSettings.oApi._fnPageChange(oSettings, "next");
fnCallbackDraw(oSettings);
nPageNumBox.val(parseInt(oSettings._iDisplayEnd / oSettings._iDisplayLength, 10));
}).bind('selectstart', function () { return false; });
nLast.click(function () {
oSettings.oApi._fnPageChange(oSettings, "last");
fnCallbackDraw(oSettings);
nPageNumBox.val(parseInt(oSettings._iDisplayEnd / oSettings._iDisplayLength,10 ));
}).bind('selectstart', function () { return false; });
nPageNumBox.focus(function () {
$(this).attr("style", "border-color: #D0B39A");
}).blur(function () {
$(this).attr("style", "border-color: #C9C9C9");
}).change(function () {
var pageValue = parseInt($(this).val(), 10);
if ((pageValue !== NaN) && pageValue > 0 && pageValue < oSettings.aoData.length) {
oSettings._iDisplayStart = $(this).val();
fnCallbackDraw(oSettings);
}
});
},
"fnUpdate": function (oSettings, fnCallbackDraw) {
if (!oSettings.aanFeatures.p) {
return;
}
/* Loop over each instance of the pager */
var an = oSettings.aanFeatures.p;
for (var i = 0, iLen = an.length; i < iLen; i++) {
//var buttons = an[i].getElementsByTagName('span');
var buttons = $(an[i]).find('span.paginate_button');
if (oSettings._iDisplayStart === 0) {
buttons.eq(0).attr("class", "paginate_disabled_first paginate_button");
buttons.eq(1).attr("class", "paginate_disabled_previous paginate_button");
}
else {
buttons.eq(0).attr("class", "paginate_enabled_first paginate_button");
buttons.eq(1).attr("class", "paginate_enabled_previous paginate_button");
}
if (oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay()) {
buttons.eq(2).attr("class", "paginate_disabled_next paginate_button");
buttons.eq(3).attr("class", "paginate_disabled_last paginate_button");
}
else {
buttons.eq(2).attr("class", "paginate_enabled_next paginate_button");
buttons.eq(3).attr("class", "paginate_enabled_last paginate_button");
}
}
}
};

@ -0,0 +1,102 @@
/**
* The built-in pagination functions provide either two buttons (forward / back)
* or lots of buttons (forward, back, first, last and individual pages). This
* plug-in meets the two in the middle providing navigation controls for forward, back, first and last.
* @name Four button navigation
* @author <a href="http://sprymedia.co.uk">Allan Jardine</a>
*
* @example
* $(document).ready(function() {
* $('#example').dataTable( {
* "sPaginationType": "four_button"
* } );
* } );
*/
$.fn.dataTableExt.oPagination.four_button = {
"fnInit": function ( oSettings, nPaging, fnCallbackDraw )
{
nFirst = document.createElement( 'span' );
nPrevious = document.createElement( 'span' );
nNext = document.createElement( 'span' );
nLast = document.createElement( 'span' );
nFirst.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sFirst ) );
nPrevious.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sPrevious ) );
nNext.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sNext ) );
nLast.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sLast ) );
nFirst.className = "paginate_button first";
nPrevious.className = "paginate_button previous";
nNext.className="paginate_button next";
nLast.className = "paginate_button last";
nPaging.appendChild( nFirst );
nPaging.appendChild( nPrevious );
nPaging.appendChild( nNext );
nPaging.appendChild( nLast );
$(nFirst).click( function () {
oSettings.oApi._fnPageChange( oSettings, "first" );
fnCallbackDraw( oSettings );
} );
$(nPrevious).click( function() {
oSettings.oApi._fnPageChange( oSettings, "previous" );
fnCallbackDraw( oSettings );
} );
$(nNext).click( function() {
oSettings.oApi._fnPageChange( oSettings, "next" );
fnCallbackDraw( oSettings );
} );
$(nLast).click( function() {
oSettings.oApi._fnPageChange( oSettings, "last" );
fnCallbackDraw( oSettings );
} );
/* Disallow text selection */
$(nFirst).bind( 'selectstart', function () { return false; } );
$(nPrevious).bind( 'selectstart', function () { return false; } );
$(nNext).bind( 'selectstart', function () { return false; } );
$(nLast).bind( 'selectstart', function () { return false; } );
},
"fnUpdate": function ( oSettings, fnCallbackDraw )
{
if ( !oSettings.aanFeatures.p )
{
return;
}
/* Loop over each instance of the pager */
var an = oSettings.aanFeatures.p;
for ( var i=0, iLen=an.length ; i<iLen ; i++ )
{
var buttons = an[i].getElementsByTagName('span');
if ( oSettings._iDisplayStart === 0 )
{
buttons[0].className = "paginate_disabled_previous";
buttons[1].className = "paginate_disabled_previous";
}
else
{
buttons[0].className = "paginate_enabled_previous";
buttons[1].className = "paginate_enabled_previous";
}
if ( oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay() )
{
buttons[2].className = "paginate_disabled_next";
buttons[3].className = "paginate_disabled_next";
}
else
{
buttons[2].className = "paginate_enabled_next";
buttons[3].className = "paginate_enabled_next";
}
}
}
};

@ -0,0 +1,139 @@
/**
* Sometimes for quick navigation, it can be useful to allow an end user to
* enter which page they wish to jump to manually. This paging control uses a
* text input box to accept new paging numbers (arrow keys are also allowed
* for), and four standard navigation buttons are also presented to the end
* user.
* @name Navigation with text input
* @author <a href="http://sprymedia.co.uk">Allan Jardine</a>
*
* @example
* $(document).ready(function() {
* $('#example').dataTable( {
* "sPaginationType": "input"
* } );
* } );
*/
$.fn.dataTableExt.oPagination.input = {
"fnInit": function ( oSettings, nPaging, fnCallbackDraw )
{
var nFirst = document.createElement( 'span' );
var nPrevious = document.createElement( 'span' );
var nNext = document.createElement( 'span' );
var nLast = document.createElement( 'span' );
var nInput = document.createElement( 'input' );
var nPage = document.createElement( 'span' );
var nOf = document.createElement( 'span' );
nFirst.innerHTML = oSettings.oLanguage.oPaginate.sFirst;
nPrevious.innerHTML = oSettings.oLanguage.oPaginate.sPrevious;
nNext.innerHTML = oSettings.oLanguage.oPaginate.sNext;
nLast.innerHTML = oSettings.oLanguage.oPaginate.sLast;
nFirst.className = "paginate_button first";
nPrevious.className = "paginate_button previous";
nNext.className="paginate_button next";
nLast.className = "paginate_button last";
nOf.className = "paginate_of";
nPage.className = "paginate_page";
if ( oSettings.sTableId !== '' )
{
nPaging.setAttribute( 'id', oSettings.sTableId+'_paginate' );
nPrevious.setAttribute( 'id', oSettings.sTableId+'_previous' );
nPrevious.setAttribute( 'id', oSettings.sTableId+'_previous' );
nNext.setAttribute( 'id', oSettings.sTableId+'_next' );
nLast.setAttribute( 'id', oSettings.sTableId+'_last' );
}
nInput.type = "text";
nInput.style.width = "15px";
nInput.style.display = "inline";
nPage.innerHTML = "Page ";
nPaging.appendChild( nFirst );
nPaging.appendChild( nPrevious );
nPaging.appendChild( nPage );
nPaging.appendChild( nInput );
nPaging.appendChild( nOf );
nPaging.appendChild( nNext );
nPaging.appendChild( nLast );
$(nFirst).click( function () {
oSettings.oApi._fnPageChange( oSettings, "first" );
fnCallbackDraw( oSettings );
} );
$(nPrevious).click( function() {
oSettings.oApi._fnPageChange( oSettings, "previous" );
fnCallbackDraw( oSettings );
} );
$(nNext).click( function() {
oSettings.oApi._fnPageChange( oSettings, "next" );
fnCallbackDraw( oSettings );
} );
$(nLast).click( function() {
oSettings.oApi._fnPageChange( oSettings, "last" );
fnCallbackDraw( oSettings );
} );
$(nInput).keyup( function (e) {
if ( e.which == 38 || e.which == 39 )
{
this.value++;
}
else if ( (e.which == 37 || e.which == 40) && this.value > 1 )
{
this.value--;
}
if ( this.value == "" || this.value.match(/[^0-9]/) )
{
/* Nothing entered or non-numeric character */
return;
}
var iNewStart = oSettings._iDisplayLength * (this.value - 1);
if ( iNewStart > oSettings.fnRecordsDisplay() )
{
/* Display overrun */
oSettings._iDisplayStart = (Math.ceil((oSettings.fnRecordsDisplay()-1) /
oSettings._iDisplayLength)-1) * oSettings._iDisplayLength;
fnCallbackDraw( oSettings );
return;
}
oSettings._iDisplayStart = iNewStart;
fnCallbackDraw( oSettings );
} );
/* Take the brutal approach to cancelling text selection */
$('span', nPaging).bind( 'mousedown', function () { return false; } );
$('span', nPaging).bind( 'selectstart', function () { return false; } );
},
"fnUpdate": function ( oSettings, fnCallbackDraw )
{
if ( !oSettings.aanFeatures.p )
{
return;
}
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 an = oSettings.aanFeatures.p;
for ( var i=0, iLen=an.length ; i<iLen ; i++ )
{
var spans = an[i].getElementsByTagName('span');
var inputs = an[i].getElementsByTagName('input');
spans[3].innerHTML = " of "+iPages
inputs[0].value = iCurrentPage;
}
}
};

@ -0,0 +1,128 @@
/**
* This modification of DataTables' standard two button pagination controls
* adds a little animation effect to the paging action by redrawing the table
* multiple times for each event, each draw progressing by one row until the
* required point in the table is reached.
* @name Scrolling navigation
* @author <a href="http://sprymedia.co.uk">Allan Jardine</a>
*
* @example
* $(document).ready(function() {
* $('#example').dataTable( {
* "sPaginationType": "scrolling"
* } );
* } );
*/
/* Time between each scrolling frame */
$.fn.dataTableExt.oPagination.iTweenTime = 100;
$.fn.dataTableExt.oPagination.scrolling = {
"fnInit": function ( oSettings, nPaging, fnCallbackDraw )
{
var oLang = oSettings.oLanguage.oPaginate;
var oClasses = oSettings.oClasses;
var fnClickHandler = function ( e ) {
if ( oSettings.oApi._fnPageChange( oSettings, e.data.action ) )
{
fnCallbackDraw( oSettings );
}
};
var sAppend = (!oSettings.bJUI) ?
'<a class="'+oSettings.oClasses.sPagePrevDisabled+'" tabindex="'+oSettings.iTabIndex+'" role="button">'+oLang.sPrevious+'</a>'+
'<a class="'+oSettings.oClasses.sPageNextDisabled+'" tabindex="'+oSettings.iTabIndex+'" role="button">'+oLang.sNext+'</a>'
:
'<a class="'+oSettings.oClasses.sPagePrevDisabled+'" tabindex="'+oSettings.iTabIndex+'" role="button"><span class="'+oSettings.oClasses.sPageJUIPrev+'"></span></a>'+
'<a class="'+oSettings.oClasses.sPageNextDisabled+'" tabindex="'+oSettings.iTabIndex+'" role="button"><span class="'+oSettings.oClasses.sPageJUINext+'"></span></a>';
$(nPaging).append( sAppend );
var els = $('a', nPaging);
var nPrevious = els[0],
nNext = els[1];
oSettings.oApi._fnBindAction( nPrevious, {action: "previous"}, function() {
/* Disallow paging event during a current paging event */
if ( typeof oSettings.iPagingLoopStart != 'undefined' && oSettings.iPagingLoopStart != -1 )
{
return;
}
oSettings.iPagingLoopStart = oSettings._iDisplayStart;
oSettings.iPagingEnd = oSettings._iDisplayStart - oSettings._iDisplayLength;
/* Correct for underrun */
if ( oSettings.iPagingEnd < 0 )
{
oSettings.iPagingEnd = 0;
}
var iTween = $.fn.dataTableExt.oPagination.iTweenTime;
var innerLoop = function () {
if ( oSettings.iPagingLoopStart > oSettings.iPagingEnd ) {
oSettings.iPagingLoopStart--;
oSettings._iDisplayStart = oSettings.iPagingLoopStart;
fnCallbackDraw( oSettings );
setTimeout( function() { innerLoop(); }, iTween );
} else {
oSettings.iPagingLoopStart = -1;
}
};
innerLoop();
} );
oSettings.oApi._fnBindAction( nNext, {action: "next"}, function() {
/* Disallow paging event during a current paging event */
if ( typeof oSettings.iPagingLoopStart != 'undefined' && oSettings.iPagingLoopStart != -1 )
{
return;
}
oSettings.iPagingLoopStart = oSettings._iDisplayStart;
/* Make sure we are not over running the display array */
if ( oSettings._iDisplayStart + oSettings._iDisplayLength < oSettings.fnRecordsDisplay() )
{
oSettings.iPagingEnd = oSettings._iDisplayStart + oSettings._iDisplayLength;
}
var iTween = $.fn.dataTableExt.oPagination.iTweenTime;
var innerLoop = function () {
if ( oSettings.iPagingLoopStart < oSettings.iPagingEnd ) {
oSettings.iPagingLoopStart++;
oSettings._iDisplayStart = oSettings.iPagingLoopStart;
fnCallbackDraw( oSettings );
setTimeout( function() { innerLoop(); }, iTween );
} else {
oSettings.iPagingLoopStart = -1;
}
};
innerLoop();
} );
},
"fnUpdate": function ( oSettings, fnCallbackDraw )
{
if ( !oSettings.aanFeatures.p )
{
return;
}
/* Loop over each instance of the pager */
var an = oSettings.aanFeatures.p;
for ( var i=0, iLen=an.length ; i<iLen ; i++ )
{
if ( an[i].childNodes.length !== 0 )
{
an[i].childNodes[0].className =
( oSettings._iDisplayStart === 0 ) ?
oSettings.oClasses.sPagePrevDisabled : oSettings.oClasses.sPagePrevEnabled;
an[i].childNodes[1].className =
( oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay() ) ?
oSettings.oClasses.sPageNextDisabled : oSettings.oClasses.sPageNextEnabled;
}
}
}
};

@ -0,0 +1,95 @@
/**
* This pagination plug-in provides a select menu with the list of the page
* numbers that are available for viewing.
* @name Select list
* @author <i>jneilliii</i>
*
* @example
* $(document).ready(function() {
* $('#example').dataTable( {
* "sPaginationType": "listbox"
* } );
* } );
*/
$.fn.dataTableExt.oPagination.listbox = {
/*
* Function: oPagination.listbox.fnInit
* Purpose: Initalise dom elements required for pagination with listbox input
* Returns: -
* Inputs: object:oSettings - dataTables settings object
* node:nPaging - the DIV which contains this pagination control
* function:fnCallbackDraw - draw function which must be called on update
*/
"fnInit": function (oSettings, nPaging, fnCallbackDraw) {
var nInput = document.createElement('select');
var nPage = document.createElement('span');
var nOf = document.createElement('span');
nOf.className = "paginate_of";
nPage.className = "paginate_page";
if (oSettings.sTableId !== '') {
nPaging.setAttribute('id', oSettings.sTableId + '_paginate');
}
nInput.style.display = "inline";
nPage.innerHTML = "Page ";
nPaging.appendChild(nPage);
nPaging.appendChild(nInput);
nPaging.appendChild(nOf);
$(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
if (this.value === "" || this.value.match(/[^0-9]/)) { /* Nothing entered or non-numeric character */
return;
}
var iNewStart = oSettings._iDisplayLength * (this.value - 1);
if (iNewStart > oSettings.fnRecordsDisplay()) { /* Display overrun */
oSettings._iDisplayStart = (Math.ceil((oSettings.fnRecordsDisplay() - 1) / oSettings._iDisplayLength) - 1) * oSettings._iDisplayLength;
fnCallbackDraw(oSettings);
return;
}
oSettings._iDisplayStart = iNewStart;
fnCallbackDraw(oSettings);
}); /* Take the brutal approach to cancelling text selection */
$('span', nPaging).bind('mousedown', function () {
return false;
});
$('span', nPaging).bind('selectstart', function () {
return false;
});
},
/*
* Function: oPagination.listbox.fnUpdate
* Purpose: Update the listbox element
* Returns: -
* Inputs: object:oSettings - dataTables settings object
* function:fnCallbackDraw - draw function which must be called on update
*/
"fnUpdate": function (oSettings, fnCallbackDraw) {
if (!oSettings.aanFeatures.p) {
return;
}
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 an = oSettings.aanFeatures.p;
for (var i = 0, iLen = an.length; i < iLen; i++) {
var spans = an[i].getElementsByTagName('span');
var inputs = an[i].getElementsByTagName('select');
var elSel = inputs[0];
if(elSel.options.length != iPages) {
elSel.options.length = 0; //clear the listbox contents
for (var j = 0; j < iPages; j++) { //add the pages
var oOption = document.createElement('option');
oOption.text = j + 1;
oOption.value = j + 1;
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;
}
}
};

@ -0,0 +1,33 @@
/**
* This plug-in will add automatic detection for currency columns to
* DataTables. Note that only $ and £ symbols are detected with this code,
* but it is trivial to add more or change the current ones. This is best used
* in conjunction with the currency sorting plug-in.
* @name Currency
* @author <a href="http://sprymedia.co.uk">Allan Jardine</a>
*/
jQuery.fn.dataTableExt.aTypes.unshift(
function ( sData )
{
var sValidChars = "0123456789.-,";
var Char;
/* Check the numeric part */
for ( i=1 ; i<sData.length ; i++ )
{
Char = sData.charAt(i);
if (sValidChars.indexOf(Char) == -1)
{
return null;
}
}
/* Check prefixed by currency */
if ( sData.charAt(0) == '$' || sData.charAt(0) == '£' )
{
return 'currency';
}
return null;
}
);

@ -0,0 +1,17 @@
/**
* Automatically detect British (dd/mm/yyyy) date types. Goes with the UK
* date sorting plug-in.
* @name UK date type detection
* @author Andy McMaster
*/
jQuery.fn.dataTableExt.aTypes.unshift(
function ( sData )
{
if (sData !== null && sData.match(/^(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[012])\/(19|20|21)\d\d$/))
{
return 'date-uk';
}
return null;
}
);

@ -0,0 +1,34 @@
/**
* Detect "file size" type columns automatically. Commonly used for computer
* file sizes, this can allow sorting to take the order of magnitude indicated
* by the label (GB etc) into account.
* @name File size
* @author <i>anjibman</i>
*/
jQuery.fn.dataTableExt.aTypes.unshift(
function ( sData )
{
var sValidChars = "0123456789";
var Char;
/* Check the numeric part */
for ( i=0 ; i<(sData.length - 3) ; i++ )
{
Char = sData.charAt(i);
if (sValidChars.indexOf(Char) == -1)
{
return null;
}
}
/* Check for size unit KB, MB or GB */
if ( sData.substring(sData.length - 2, sData.length) == "KB"
|| sData.substring(sData.length - 2, sData.length) == "MB"
|| sData.substring(sData.length - 2, sData.length) == "GB" )
{
return 'file-size';
}
return null;
}
);

@ -0,0 +1,21 @@
/**
* This plug-in will strip out non-numeric formatting characters such that a
* formatted number (for example 1,000,000) can be detected automatically and
* sorted numerically. Note that characters a-z are not automatically removed,
* otherwise there is a risk of detecting columns as numeric which should not
* be. Also note that the jQuery 1.7 method isNumeric is used, so jQuery 1.7
* is required.
* @name Formatted numbers
* @author <a href="http://sprymedia.co.uk">Allan Jardine</a>
*/
jQuery.fn.dataTableExt.aTypes.unshift(
function ( sData )
{
var deformatted = sData.replace(/[^\d\-\.\/a-zA-Z]/g,'');
if ( $.isNumeric( deformatted ) ) {
return 'formatted-num';
}
return null;
}
);

@ -0,0 +1,16 @@
/**
* Automatically detect IP addresses in dot notation. Goes perfectly with the
* IP address sorting function.
* @name IP address detection
* @author Brad Wasson
*/
jQuery.fn.dataTableExt.aTypes.unshift(
function ( sData )
{
if (/^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}$/.test(sData)) {
return 'ip-address';
}
return null;
}
);

@ -0,0 +1,49 @@
/**
* This type-detection plug-in will look at an HTML string from a data cell,
* strip the HTML tags and then check to see if the remaining data is numeric.
* If it is, then the data can be sorted numerically with the Numbers with HTML
* sorting plug-in.
* @name Numbers with HTML
* @author <a href="http://sprymedia.co.uk">Allan Jardine</a>
*/
jQuery.fn.dataTableExt.aTypes.unshift( function ( sData )
{
sData = typeof sData.replace == 'function' ?
sData.replace( /<.*?>/g, "" ) : sData;
sData = $.trim(sData);
var sValidFirstChars = "0123456789-";
var sValidChars = "0123456789.";
var Char;
var bDecimal = false;
/* Check for a valid first char (no period and allow negatives) */
Char = sData.charAt(0);
if (sValidFirstChars.indexOf(Char) == -1)
{
return null;
}
/* Check all the other characters are valid */
for ( var i=1 ; i<sData.length ; i++ )
{
Char = sData.charAt(i);
if (sValidChars.indexOf(Char) == -1)
{
return null;
}
/* Only allowed one decimal place... */
if ( Char == "." )
{
if ( bDecimal )
{
return null;
}
bDecimal = true;
}
}
return 'num-html';
} );

@ -0,0 +1,37 @@
/**
* Automatically detect numbers which use a comma in the place of a decimal
* point to allow them to be sorted numerically.
* @name Commas for decimal place
* @author <a href="http://sprymedia.co.uk">Allan Jardine</a>
*/
jQuery.fn.dataTableExt.aTypes.unshift(
function ( sData )
{
var sValidChars = "0123456789-,";
var Char;
var bDecimal = false;
/* Check the numeric part */
for ( i=0 ; i<sData.length ; i++ )
{
Char = sData.charAt(i);
if (sValidChars.indexOf(Char) == -1)
{
return null;
}
/* Only allowed one decimal place... */
if ( Char == "," )
{
if ( bDecimal )
{
return null;
}
bDecimal = true;
}
}
return 'numeric-comma';
}
);
Loading…
Cancel
Save