From 4f29d7fda6e04574c8a47e7628a039b074c8ef66 Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Wed, 8 Jan 2014 17:06:10 +0000 Subject: [PATCH] Major update to doc comment formatting for new DataTables web-site Also correct a load of JS errors such as leaking variables and use consistent formatting. --- api/average().js | 2 + api/fnAddDataAndDisplay.js | 15 +-- api/fnAddTr.js | 12 +- api/fnColumnIndexToVisible.js | 5 +- api/fnDataUpdate.js | 9 +- api/fnDisplayRow.js | 13 +- api/fnDisplayStart.js | 11 +- api/fnFakeRowspan.js | 31 +++-- api/fnFilterAll.js | 9 +- api/fnFilterClear.js | 19 +-- api/fnFilterOnReturn.js | 7 +- api/fnFindCellRowIndexes.js | 14 +-- api/fnFindCellRowNodes.js | 13 +- api/fnGetAdjacentTr.js | 15 +-- api/fnGetColumnData.js | 67 ++++++---- api/fnGetColumnIndex.js | 9 +- api/fnGetHiddenNodes.js | 13 +- api/fnGetTd.js | 11 +- api/fnGetTds.js | 17 +-- api/fnLengthChange.js | 15 +-- api/fnMultiFilter.js | 7 +- api/fnPagingInfo.js | 7 +- api/fnProcessingIndicator.js | 3 +- api/fnReloadAjax.js | 13 +- api/fnSetFilteringDelay.js | 18 +-- api/fnSortNeutral.js | 11 +- api/fnStandingRedraw.js | 7 +- api/fnVisibleToColumnIndex.js | 7 +- api/page.jumpToData().js | 20 +++ api/sum().js | 5 +- .../row-based/TableTools.ShowSelectedOnly.js | 15 ++- filtering/row-based/range_dates.js | 31 ++--- filtering/row-based/range_numbers.js | 19 +-- filtering/type-based/accent-neutralise.js | 56 +++++++++ filtering/type-based/html.js | 38 +++--- filtering/type-based/phoneNumber.js | 31 +++++ pagination/ellipses.js | 22 ++-- pagination/extjs.js | 5 +- pagination/four_button.js | 45 ++++--- pagination/input.js | 46 +++---- pagination/scrolling.js | 43 +++---- pagination/select.js | 7 +- sorting/alt-string.js | 14 ++- sorting/anti-the.js | 12 +- sorting/chinese-string.js | 28 +++-- sorting/currency.js | 17 ++- sorting/custom-data-source/dom-checkbox.js | 12 +- sorting/custom-data-source/dom-select.js | 13 +- sorting/custom-data-source/dom-text.js | 13 +- sorting/date-dd-MMM-yyyy.js | 35 ++++-- sorting/date-de.js | 64 ++++++++++ sorting/date-eu.js | 33 +++-- sorting/date-euro.js | 25 ++-- sorting/date-uk.js | 14 ++- sorting/datetime-us.js | 116 +++++++++++------- sorting/enum.js | 16 ++- sorting/file-size.js | 18 ++- sorting/formatted-numbers.js | 21 +++- sorting/ip-address.js | 10 +- sorting/monthYear.js | 12 +- sorting/natural.js | 58 ++++++--- sorting/num-html.js | 17 ++- sorting/numeric-comma.js | 15 ++- sorting/percent.js | 17 ++- sorting/persian.js | 26 ++-- sorting/scientific.js | 14 ++- sorting/signed-num.js | 12 +- sorting/title-numeric.js | 21 +++- sorting/title-string.js | 18 ++- type-detection/currency.js | 12 +- type-detection/date-uk.js | 7 +- type-detection/file-size.js | 11 +- type-detection/formatted-num.js | 15 ++- type-detection/ip-address.js | 3 +- type-detection/num-html.js | 30 +++-- type-detection/numeric-comma.js | 12 +- 76 files changed, 1026 insertions(+), 498 deletions(-) create mode 100644 api/page.jumpToData().js create mode 100644 filtering/type-based/accent-neutralise.js create mode 100644 filtering/type-based/phoneNumber.js create mode 100644 sorting/date-de.js diff --git a/api/average().js b/api/average().js index b655486..6c2a3f0 100644 --- a/api/average().js +++ b/api/average().js @@ -1,6 +1,8 @@ /** * Average the values in a data set. + * * @name average() + * @summary * @author [Allan Jardine](http://sprymedia.co.uk) * @requires DataTables 1.10+ * diff --git a/api/fnAddDataAndDisplay.js b/api/fnAddDataAndDisplay.js index ead91a2..cb0cc2a 100644 --- a/api/fnAddDataAndDisplay.js +++ b/api/fnAddDataAndDisplay.js @@ -6,9 +6,10 @@ * This function is a drop in replacement for fnAddData with one important * exception, it will only take a 1D array or an object, and not a 2D array * (i.e. it will not add multiple rows like fnAddData). + * * @name fnAddDataAndDisplay - * @anchor fnAddDataAndDisplay - * @author Allan Jardine + * @summary + * @author [Allan Jardine](http://sprymedia.co.uk) * * @example * $(document).ready(function() { @@ -17,18 +18,18 @@ * } ); */ -$.fn.dataTableExt.oApi.fnAddDataAndDisplay = function ( oSettings, aData ) +jQuery.fn.dataTableExt.oApi.fnAddDataAndDisplay = function ( oSettings, aData ) { /* Add the data */ var iAdded = this.oApi._fnAddData( oSettings, aData ); var nAdded = oSettings.aoData[ iAdded ].nTr; - + /* Need to re-filter and re-sort the table to get positioning correct, not perfect * as this will actually redraw the table on screen, but the update should be so fast (and * possibly not alter what is already on display) that the user will not notice */ this.oApi._fnReDraw( oSettings ); - + /* Find it's position in the table */ var iPos = -1; for( var i=0, iLen=oSettings.aiDisplay.length ; i= 0 ) { oSettings._iDisplayStart = ( Math.floor(i / oSettings._iDisplayLength) ) * oSettings._iDisplayLength; this.oApi._fnCalculateEnd( oSettings ); } - + this.oApi._fnDraw( oSettings ); return { "nTr": nAdded, diff --git a/api/fnAddTr.js b/api/fnAddTr.js index 503c74d..0c02ecd 100644 --- a/api/fnAddTr.js +++ b/api/fnAddTr.js @@ -1,15 +1,16 @@ /** * Take a TR element and add it to a DataTables table. Useful for maintaining * custom classes and other attributes. + * * @name fnAddTr - * @anchor fnAddTr - * @author Allan Jardine + * @summary + * @author [Allan Jardine](http://sprymedia.co.uk) * * @example * */ -$.fn.dataTableExt.oApi.fnAddTr = function ( oSettings, nTr, bRedraw ) { +jQuery.fn.dataTableExt.oApi.fnAddTr = function ( oSettings, nTr, bRedraw ) { if ( typeof bRedraw == 'undefined' ) { bRedraw = true; @@ -24,7 +25,8 @@ $.fn.dataTableExt.oApi.fnAddTr = function ( oSettings, nTr, bRedraw ) { var aData = []; var aInvisible = []; - for ( var i=0 ; i= 0 ; i-- ) + for ( i = (aInvisible.length - 1) ; i >= 0 ; i-- ) { oSettings.aoData[iIndex]._anHidden[ i ] = nTds[aInvisible[i]]; nTr.removeChild( nTds[aInvisible[i]] ); diff --git a/api/fnColumnIndexToVisible.js b/api/fnColumnIndexToVisible.js index 8c03a3b..f3aa858 100644 --- a/api/fnColumnIndexToVisible.js +++ b/api/fnColumnIndexToVisible.js @@ -4,9 +4,10 @@ * index value for the column positions. This function converts the data * column index (i.e. all columns regardless of visibility) into a visible * column index. + * * @name fnColumnIndexToVisible - * @anchor fnColumnIndexToVisible - * @author Allan Jardine + * @summary + * @author [Allan Jardine](http://sprymedia.co.uk) * * @example * diff --git a/api/fnDataUpdate.js b/api/fnDataUpdate.js index 1b06a2b..eed9b04 100644 --- a/api/fnDataUpdate.js +++ b/api/fnDataUpdate.js @@ -1,18 +1,19 @@ /** * Update the internal data for a TR element based on what is used in the * DOM. You will likely want to call fnDraw() after this function. + * * @name fnDataUpdate - * @anchor fnDataUpdate + * @summary * @author Lior Gerson * * @example * */ -$.fn.dataTableExt.oApi.fnDataUpdate = function ( oSettings, nRowObject, iRowIndex ) +jQuery.fn.dataTableExt.oApi.fnDataUpdate = function ( oSettings, nRowObject, iRowIndex ) { - $(nRowObject).find("TD").each( function(i) { + jQuery(nRowObject).find("TD").each( function(i) { var iColIndex = oSettings.oApi._fnVisibleToColumnIndex( oSettings, i ); - oSettings.oApi._fnSetCellData( oSettings, iRowIndex, iColIndex, $(this).html() ); + oSettings.oApi._fnSetCellData( oSettings, iRowIndex, iColIndex, jQuery(this).html() ); } ); }; diff --git a/api/fnDisplayRow.js b/api/fnDisplayRow.js index 903f001..d7636d0 100644 --- a/api/fnDisplayRow.js +++ b/api/fnDisplayRow.js @@ -1,8 +1,9 @@ /** * Take a TR element and alter the table's paging to show the TR in question. + * * @name fnDisplayRow - * @anchor fnDisplayRow - * @author Allan Jardine + * @summary + * @author [Allan Jardine](http://sprymedia.co.uk) * * @example * $(document).ready(function() { @@ -12,14 +13,14 @@ * } ); */ -$.fn.dataTableExt.oApi.fnDisplayRow = function ( oSettings, nRow ) +jQuery.fn.dataTableExt.oApi.fnDisplayRow = function ( oSettings, nRow ) { // Account for the "display" all case - row is already displayed if ( oSettings._iDisplayLength == -1 ) { return; } - + // Find the node in the table var iPos = -1; for( var i=0, iLen=oSettings.aiDisplay.length ; i= 0 ) { oSettings._iDisplayStart = ( Math.floor(i / oSettings._iDisplayLength) ) * oSettings._iDisplayLength; this.oApi._fnCalculateEnd( oSettings ); } - + this.oApi._fnDraw( oSettings ); }; diff --git a/api/fnDisplayStart.js b/api/fnDisplayStart.js index 56cd5c5..523499b 100644 --- a/api/fnDisplayStart.js +++ b/api/fnDisplayStart.js @@ -1,24 +1,25 @@ /** * Set the point at which DataTables will start it's display of data in the * table. + * * @name fnDisplayStart - * @anchor fnDisplayStart - * @author Allan Jardine + * @summary + * @author [Allan Jardine](http://sprymedia.co.uk) * * @example * */ -$.fn.dataTableExt.oApi.fnDisplayStart = function ( oSettings, iStart, bRedraw ) +jQuery.fn.dataTableExt.oApi.fnDisplayStart = function ( oSettings, iStart, bRedraw ) { if ( typeof bRedraw == 'undefined' ) { bRedraw = true; } - + oSettings._iDisplayStart = iStart; oSettings.oApi._fnCalculateEnd( oSettings ); - + if ( bRedraw ) { oSettings.oApi._fnDraw( oSettings ); diff --git a/api/fnFakeRowspan.js b/api/fnFakeRowspan.js index 3634cfc..dd8bd89 100644 --- a/api/fnFakeRowspan.js +++ b/api/fnFakeRowspan.js @@ -1,36 +1,33 @@ /** * Creates rowspan cells in a column when there are two or more cells in a * row with the same content, effectively grouping them together visually. - * Note - this plug-in currently only operates correctly with - * server-side processing. + * *Note* - this plug-in currently only operates correctly with + * *server-side processing*. + * * @name fnFakeRowspan - * @anchor fnFakeRowspan + * @summary * @author Fredrik Wendel * * @example * $('#example').dataTable().fnFakeRowspan(3); */ -$.fn.dataTableExt.oApi.fnFakeRowspan = function ( oSettings, iColumn, bCaseSensitive ) { +jQuery.fn.dataTableExt.oApi.fnFakeRowspan = function ( oSettings, iColumn, bCaseSensitive ) { /* Fail silently on missing/errorenous parameter data. */ if (isNaN(iColumn)) { return false; } - + if (iColumn < 0 || iColumn > oSettings.aoColumns.length-1) { alert ('Invalid column number choosen, must be between 0 and ' + (oSettings.aoColumns.length-1)); return false; } - - var oSettings = oSettings, - iColumn = iColumn, - bCaseSensitive = (typeof(bCaseSensitive) != 'boolean' ? true : bCaseSensitive); - - oSettings.aoDrawCallback.push({ "fn": fakeRowspan, "sName": "fnFakeRowspan" }); - + + bCaseSensitive = (typeof(bCaseSensitive) != 'boolean' ? true : bCaseSensitive); + function fakeRowspan () { var firstOccurance = null, - value = null, + value = null, rowspan = 0; jQuery.each(oSettings.aoData, function (i, oData) { var val = oData._aData[iColumn], @@ -45,17 +42,19 @@ $.fn.dataTableExt.oApi.fnFakeRowspan = function ( oSettings, iColumn, bCaseSensi firstOccurance = cell; rowspan = 0; } - + if (val == value) { rowspan++; } - + if (firstOccurance !== null && val == value && rowspan > 1) { oData.nTr.removeChild(cell); firstOccurance.rowSpan = rowspan; } }); } - + + oSettings.aoDrawCallback.push({ "fn": fakeRowspan, "sName": "fnFakeRowspan" }); + return this; }; diff --git a/api/fnFilterAll.js b/api/fnFilterAll.js index 292b6cc..194f3be 100644 --- a/api/fnFilterAll.js +++ b/api/fnFilterAll.js @@ -2,9 +2,10 @@ * Apply the same filter to all DataTable instances on a particular page. The * function call exactly matches that used by fnFilter() so regular expression * and individual column sorting can be used. + * * @name fnFilterAll - * @anchor fnFilterAll - * @author Kristoffer Karlström + * @summary + * @author [Kristoffer Karlström](http://www.kmmtiming.se/) * * @example * $(document).ready(function() { @@ -17,9 +18,9 @@ * }); */ -$.fn.dataTableExt.oApi.fnFilterAll = function(oSettings, sInput, iColumn, bRegex, bSmart) { +jQuery.fn.dataTableExt.oApi.fnFilterAll = function(oSettings, sInput, iColumn, bRegex, bSmart) { var settings = $.fn.dataTableSettings; - + for ( var i=0 ; iAllan Jardine + * @summary + * @author [Allan Jardine](http://sprymedia.co.uk) * * @example * $(document).ready(function() { @@ -18,29 +19,31 @@ * } ); */ -$.fn.dataTableExt.oApi.fnFilterClear = function ( oSettings ) +jQuery.fn.dataTableExt.oApi.fnFilterClear = function ( oSettings ) { + var i, iLen; + /* Remove global filter */ oSettings.oPreviousSearch.sSearch = ""; - + /* Remove the text of the global filter in the input boxes */ if ( typeof oSettings.aanFeatures.f != 'undefined' ) { var n = oSettings.aanFeatures.f; - for ( var i=0, iLen=n.length ; iJon Ranes + * @summary + * @author [Jon Ranes](http://www.mvccms.com/) * * @example * $(document).ready(function() { @@ -14,7 +15,7 @@ jQuery.fn.dataTableExt.oApi.fnFilterOnReturn = function (oSettings) { var _that = this; - + this.each(function (i) { $.fn.dataTableExt.iApiIndex = i; var $this = this; diff --git a/api/fnFindCellRowIndexes.js b/api/fnFindCellRowIndexes.js index 09abb0d..f78a738 100644 --- a/api/fnFindCellRowIndexes.js +++ b/api/fnFindCellRowIndexes.js @@ -3,9 +3,10 @@ * can be restricted to a single column). The return value is an array with * the data indexes (from DataTables' internal data store) for any rows which * match. + * * @name fnFindCellRowIndexes - * @anchor fnFindCellRowIndexes - * @author Allan Jardine + * @summary + * @author [Allan Jardine](http://sprymedia.co.uk) * * @example * $(document).ready(function() { @@ -17,16 +18,16 @@ * } ); */ -$.fn.dataTableExt.oApi.fnFindCellRowIndexes = function ( oSettings, sSearch, iColumn ) +jQuery.fn.dataTableExt.oApi.fnFindCellRowIndexes = function ( oSettings, sSearch, iColumn ) { var i,iLen, j, jLen, aOut = [], aData; - + for ( i=0, iLen=oSettings.aoData.length ; iAllan Jardine + * @summary + * @author [Allan Jardine](http://sprymedia.co.uk) * * @example * $(document).ready(function() { @@ -17,16 +18,16 @@ * } ); */ -$.fn.dataTableExt.oApi.fnFindCellRowNodes = function ( oSettings, sSearch, iColumn ) +jQuery.fn.dataTableExt.oApi.fnFindCellRowNodes = function ( oSettings, sSearch, iColumn ) { var i,iLen, j, jLen, aOut = [], aData; - + for ( i=0, iLen=oSettings.aoData.length ; iAllan Jardine + * @summary + * @author [Allan Jardine](http://sprymedia.co.uk) * * @example * $(document).ready(function() { @@ -20,11 +21,11 @@ * } ); */ -$.fn.dataTableExt.oApi.fnGetAdjacentTr = function ( oSettings, nTr, bNext ) +jQuery.fn.dataTableExt.oApi.fnGetAdjacentTr = function ( oSettings, nTr, bNext ) { /* Find the node's position in the aoData store */ var iCurrent = oSettings.oApi._fnNodeToDataIndex( oSettings, nTr ); - + /* Convert that to a position in the display array */ var iDisplayIndex = $.inArray( iCurrent, oSettings.aiDisplay ); if ( iDisplayIndex == -1 ) @@ -32,17 +33,17 @@ $.fn.dataTableExt.oApi.fnGetAdjacentTr = function ( oSettings, nTr, bNext ) /* Not in the current display */ return null; } - + /* Move along the display array as needed */ iDisplayIndex += (typeof bNext=='undefined' || bNext) ? 1 : -1; - + /* Check that it within bounds */ if ( iDisplayIndex < 0 || iDisplayIndex >= oSettings.aiDisplay.length ) { /* There is no next/previous element */ return null; } - + /* Return the target node from the aoData store */ return oSettings.aoData[ oSettings.aiDisplay[ iDisplayIndex ] ].nTr; }; diff --git a/api/fnGetColumnData.js b/api/fnGetColumnData.js index 03b719b..9ed4b4d 100644 --- a/api/fnGetColumnData.js +++ b/api/fnGetColumnData.js @@ -1,9 +1,10 @@ /** * Return an array of table values from a particular column, with various * filtering options. + * * @name fnGetColumnData - * @anchor fnGetColumnData - * @author Benedikt Forchhammer + * @summary + * @author [Benedikt Forchhammer](http://mind2.de) * * @example * @@ -11,41 +12,59 @@ jQuery.fn.dataTableExt.oApi.fnGetColumnData = function ( oSettings, iColumn, bUnique, bFiltered, bIgnoreEmpty ) { // check that we have a column id - if ( typeof iColumn == "undefined" ) return []; - + if ( typeof iColumn == "undefined" ) { + return []; + } + // by default we only wany unique data - if ( typeof bUnique == "undefined" ) bUnique = true; - + if ( typeof bUnique == "undefined" ) { + bUnique = true; + } + // by default we do want to only look at filtered data - if ( typeof bFiltered == "undefined" ) bFiltered = true; - + if ( typeof bFiltered == "undefined" ) { + bFiltered = true; + } + // by default we do not wany to include empty values - if ( typeof bIgnoreEmpty == "undefined" ) bIgnoreEmpty = true; - + if ( typeof bIgnoreEmpty == "undefined" ) { + bIgnoreEmpty = true; + } + // list of rows which we're going to loop through var aiRows; - + // use only filtered rows - if (bFiltered == true) aiRows = oSettings.aiDisplay; + if (bFiltered === true) { + aiRows = oSettings.aiDisplay; + } // use all rows - else aiRows = oSettings.aiDisplayMaster; // all row numbers - + else { + aiRows = oSettings.aiDisplayMaster; // all row numbers + } + // set up data array - var asResultData = new Array(); - + var asResultData = []; + for (var i=0,c=aiRows.length; i -1) continue; - + else if (bUnique === true && jQuery.inArray(sValue, asResultData) > -1) { + continue; + } + // else push the value onto the result data array - else asResultData.push(sValue); + else { + asResultData.push(sValue); + } } - + return asResultData; }; diff --git a/api/fnGetColumnIndex.js b/api/fnGetColumnIndex.js index 7d2d536..785b8ea 100644 --- a/api/fnGetColumnIndex.js +++ b/api/fnGetColumnIndex.js @@ -4,15 +4,16 @@ * needs to change due to an added or removed column. This plug-in function * will match a given string to the title of a column in the table and return * the column index, helping to overcome this problem. + * * @name fnGetColumnIndex - * @anchor fnGetColumnIndex - * @author Michael Ross + * @summary + * @author [Michael Ross](http://www.rosstechassociates.com/) * * @example * */ -$.fn.dataTableExt.oApi.fnGetColumnIndex = function ( oSettings, sCol ) +jQuery.fn.dataTableExt.oApi.fnGetColumnIndex = function ( oSettings, sCol ) { var cols = oSettings.aoColumns; for ( var x=0, xLen=cols.length ; xAllan Jardine + * @summary + * @author [Allan Jardine](http://sprymedia.co.uk) */ -$.fn.dataTableExt.oApi.fnGetHiddenNodes = function ( settings ) +jQuery.fn.dataTableExt.oApi.fnGetHiddenNodes = function ( settings ) { var nodes; - var display = $('tbody tr', settings.nTable); + var display = jQuery('tbody tr', settings.nTable); - if ( $.fn.dataTable.versionCheck ) { + if ( jQuery.fn.dataTable.versionCheck ) { // DataTables 1.10 - var api = new $.fn.dataTable.Api( settings ); + var api = new jQuery.fn.dataTable.Api( settings ); nodes = api.rows().nodes().toArray(); } else { diff --git a/api/fnGetTd.js b/api/fnGetTd.js index 728d95b..cfbe873 100644 --- a/api/fnGetTd.js +++ b/api/fnGetTd.js @@ -4,9 +4,10 @@ * DOM methods, jQuery or whatever, it becomes a lot more complicated when * taking into account hidden rows and columns. This function can be used to * overcome these difficulties. + * * @name fnGetTd - * @anchor fnGetTd - * @author Allan Jardine + * @summary + * @author [Allan Jardine](http://sprymedia.co.uk) * * @example * $(document).ready(function() { @@ -18,12 +19,12 @@ * } ); */ -$.fn.dataTableExt.oApi.fnGetTd = function ( oSettings, mTr, iTd, bVisOnly ) +jQuery.fn.dataTableExt.oApi.fnGetTd = function ( oSettings, mTr, iTd, bVisOnly ) { /* Take either a TR node or aoData index as the mTr property */ - var iRow = (typeof mTr == 'object') ? + var iRow = (typeof mTr == 'object') ? oSettings.oApi._fnNodeToDataIndex(oSettings, mTr) : mTr; - + if ( typeof bVisOnly == 'undefined' && !bVisOnly ) { /* Looking at both visible and hidden TD elements - convert to visible index, if not present diff --git a/api/fnGetTds.js b/api/fnGetTds.js index 3ff4bfb..fc16f75 100644 --- a/api/fnGetTds.js +++ b/api/fnGetTds.js @@ -1,9 +1,10 @@ /** * Get an array of TD nodes from DataTables for a given row, including any * column elements which are hidden. + * * @name fnGetTds - * @anchor fnGetTds - * @author Allan Jardine + * @summary + * @author [Allan Jardine](http://sprymedia.co.uk) * * @example * $(document).ready(function() { @@ -15,18 +16,18 @@ * } ); */ -$.fn.dataTableExt.oApi.fnGetTds = function ( oSettings, mTr ) +jQuery.fn.dataTableExt.oApi.fnGetTds = function ( oSettings, mTr ) { var anTds = []; var anVisibleTds = []; var iCorrector = 0; var nTd, iColumn, iColumns; - + /* Take either a TR node or aoData index as the mTr property */ - var iRow = (typeof mTr == 'object') ? + var iRow = (typeof mTr == 'object') ? oSettings.oApi._fnNodeToDataIndex(oSettings, mTr) : mTr; var nTr = oSettings.aoData[iRow].nTr; - + /* Get an array of the visible TD elements */ for ( iColumn=0, iColumns=nTr.childNodes.length ; iColumnPedro Alves + * @summary + * @author [Pedro Alves](http://www.webdetails.pt/) * * @example * $(document).ready(function() { @@ -12,11 +13,11 @@ * } ); */ -$.fn.dataTableExt.oApi.fnLengthChange = function ( oSettings, iDisplay ) +jQuery.fn.dataTableExt.oApi.fnLengthChange = function ( oSettings, iDisplay ) { oSettings._iDisplayLength = iDisplay; oSettings.oApi._fnCalculateEnd( oSettings ); - + /* If we have space to show extra rows (backing up from the end point - then do so */ if ( oSettings._iDisplayEnd == oSettings.aiDisplay.length ) { @@ -26,14 +27,14 @@ $.fn.dataTableExt.oApi.fnLengthChange = function ( oSettings, iDisplay ) oSettings._iDisplayStart = 0; } } - + if ( oSettings._iDisplayLength == -1 ) { oSettings._iDisplayStart = 0; } - + oSettings.oApi._fnDraw( oSettings ); - + if ( oSettings.aanFeatures.l ) { $('select', oSettings.aanFeatures.l).val( iDisplay ); diff --git a/api/fnMultiFilter.js b/api/fnMultiFilter.js index 9e33cb2..406106e 100644 --- a/api/fnMultiFilter.js +++ b/api/fnMultiFilter.js @@ -4,9 +4,10 @@ * processing). Used in combination with the column sName parameter, simply * pass in an object with the key/value pair being the column you wish to * search on, and the value you wish to search for. + * * @name fnMultiFilter - * @anchor fnMultiFilter - * @author mrkevans + * @summary + * @author _mrkevans_ * * @example * $(document).ready(function() { @@ -23,7 +24,7 @@ * } ); */ -$.fn.dataTableExt.oApi.fnMultiFilter = function( oSettings, oData ) { +jQuery.fn.dataTableExt.oApi.fnMultiFilter = function( oSettings, oData ) { for ( var key in oData ) { if ( oData.hasOwnProperty(key) ) diff --git a/api/fnPagingInfo.js b/api/fnPagingInfo.js index 0a2d4bf..c8e05c0 100644 --- a/api/fnPagingInfo.js +++ b/api/fnPagingInfo.js @@ -2,9 +2,10 @@ * Get information about the paging settings that DataTables is currently * using to display each page, including the number of records shown, start * and end points in the data set etc. + * * @name fnPagingInfo - * @anchor fnPagingInfo - * @author Allan Jardine + * @summary + * @author [Allan Jardine](http://sprymedia.co.uk) * * @example * $(document).ready(function() { @@ -16,7 +17,7 @@ * } ); */ -$.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings ) +jQuery.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings ) { return { "iStart": oSettings._iDisplayStart, diff --git a/api/fnProcessingIndicator.js b/api/fnProcessingIndicator.js index 6d2b91d..a65a5e2 100644 --- a/api/fnProcessingIndicator.js +++ b/api/fnProcessingIndicator.js @@ -3,8 +3,9 @@ * data loading from the server) it can be useful to make use of the * 'processing' indicator built-into DataTables. This plug-in function * exposes the internal DataTables function so it can be used for exactly this. + * * @name fnProcessingIndicator - * @anchor fnProcessingIndicator + * @summary * @author Allan Chappell * * @example diff --git a/api/fnReloadAjax.js b/api/fnReloadAjax.js index 98e5ef5..ccff962 100644 --- a/api/fnReloadAjax.js +++ b/api/fnReloadAjax.js @@ -3,9 +3,10 @@ * time, however it can be useful to re-read an Ajax source and have the table * update. Typically you would need to use the fnClearTable() and fnAddData() * functions, however this wraps it all up in a single function call. + * * @name fnReloadAjax - * @anchor fnReloadAjax - * @author Allan Jardine + * @summary + * @author [Allan Jardine](http://sprymedia.co.uk) * * @example * // Example call to load a new file @@ -15,13 +16,13 @@ * oTable.fnReloadAjax(); */ -$.fn.dataTableExt.oApi.fnReloadAjax = function ( oSettings, sNewSource, fnCallback, bStandingRedraw ) +jQuery.fn.dataTableExt.oApi.fnReloadAjax = function ( oSettings, sNewSource, fnCallback, bStandingRedraw ) { // DataTables 1.10 compatibility - if 1.10 then `versionCheck` exists. // 1.10's API has ajax reloading built in, so we use those abilities // directly. - if ( $.fn.dataTable.versionCheck ) { - var api = new $.fn.dataTable.Api( oSettings ); + if ( jQuery.fn.dataTable.versionCheck ) { + var api = new jQuery.fn.dataTable.Api( oSettings ); if ( sNewSource ) { api.ajax.url( sNewSource ).load( fnCallback, !bStandingRedraw ); @@ -61,7 +62,7 @@ $.fn.dataTableExt.oApi.fnReloadAjax = function ( oSettings, sNewSource, fnCallba { that.oApi._fnAddData( oSettings, aData[i] ); } - + oSettings.aiDisplay = oSettings.aiDisplayMaster.slice(); that.fnDraw(); diff --git a/api/fnSetFilteringDelay.js b/api/fnSetFilteringDelay.js index 2a5ddf9..c55b044 100644 --- a/api/fnSetFilteringDelay.js +++ b/api/fnSetFilteringDelay.js @@ -2,8 +2,8 @@ * Enables filtration delay for keeping the browser more responsive while * searching for a longer keyword. * @name fnSetFilteringDelay - * @anchor fnSetFilteringDelay - * @author Zygimantas Berziunas, Allan Jardine and vex + * @summary + * @author [Zygimantas Berziunas](http://www.zygimantas.com/), [Allan Jardine](http://www.sprymedia.co.uk/) and _vex_ * * @example * $(document).ready(function() { @@ -17,28 +17,28 @@ jQuery.fn.dataTableExt.oApi.fnSetFilteringDelay = function ( oSettings, iDelay ) if ( iDelay === undefined ) { iDelay = 250; } - + this.each( function ( i ) { $.fn.dataTableExt.iApiIndex = i; var - $this = this, - oTimerId = null, + $this = this, + oTimerId = null, sPreviousSearch = null, anControl = $( 'input', _that.fnSettings().aanFeatures.f ); - + anControl.unbind( 'keyup' ).bind( 'keyup', function() { var $$this = $this; - + if (sPreviousSearch === null || sPreviousSearch != anControl.val()) { window.clearTimeout(oTimerId); - sPreviousSearch = anControl.val(); + sPreviousSearch = anControl.val(); oTimerId = window.setTimeout(function() { $.fn.dataTableExt.iApiIndex = i; _that.fnFilter( anControl.val() ); }, iDelay); } }); - + return this; } ); return this; diff --git a/api/fnSortNeutral.js b/api/fnSortNeutral.js index e93b4a8..056cfe8 100644 --- a/api/fnSortNeutral.js +++ b/api/fnSortNeutral.js @@ -5,9 +5,10 @@ * initialisation, it can sometimes be useful to restore the original order * after sorting has already occurred - which is exactly what this function * does. + * * @name fnSortNeutral - * @anchor fnSortNeutral - * @author Allan Jardine + * @summary + * @author [Allan Jardine](http://sprymedia.co.uk) * * @example * $(document).ready(function() { @@ -18,11 +19,11 @@ * } ); */ -$.fn.dataTableExt.oApi.fnSortNeutral = function ( oSettings ) +jQuery.fn.dataTableExt.oApi.fnSortNeutral = function ( oSettings ) { /* Remove any current sorting */ oSettings.aaSorting = []; - + /* Sort display arrays so we get them in numerical order */ oSettings.aiDisplay.sort( function (x,y) { return x-y; @@ -30,7 +31,7 @@ $.fn.dataTableExt.oApi.fnSortNeutral = function ( oSettings ) oSettings.aiDisplayMaster.sort( function (x,y) { return x-y; } ); - + /* Redraw */ oSettings.oApi._fnReDraw( oSettings ); }; diff --git a/api/fnStandingRedraw.js b/api/fnStandingRedraw.js index fa49da0..7b9b07f 100644 --- a/api/fnStandingRedraw.js +++ b/api/fnStandingRedraw.js @@ -1,8 +1,9 @@ /** * Redraw the table (i.e. fnDraw) to take account of sorting and filtering, * but retain the current pagination settings. + * * @name fnStandingRedraw - * @anchor fnStandingRedraw + * @summary * @author Jonathan Hoguet * * @example @@ -12,7 +13,7 @@ * } ); */ -$.fn.dataTableExt.oApi.fnStandingRedraw = function(oSettings) { +jQuery.fn.dataTableExt.oApi.fnStandingRedraw = function(oSettings) { if(oSettings.oFeatures.bServerSide === false){ var before = oSettings._iDisplayStart; @@ -22,7 +23,7 @@ $.fn.dataTableExt.oApi.fnStandingRedraw = function(oSettings) { oSettings._iDisplayStart = before; oSettings.oApi._fnCalculateEnd(oSettings); } - + // draw the 'current' page oSettings.oApi._fnDraw(oSettings); }; diff --git a/api/fnVisibleToColumnIndex.js b/api/fnVisibleToColumnIndex.js index 42385c4..1053e0d 100644 --- a/api/fnVisibleToColumnIndex.js +++ b/api/fnVisibleToColumnIndex.js @@ -3,15 +3,16 @@ * fnSetColumnVis) it removes these elements from the DOM, effecting the index * value for the column positions. This function converts the visible column * index into a data column index (i.e. all columns regardless of visibility). + * * @name fnVisibleToColumnIndex - * @anchor fnVisibleToColumnIndex - * @author Allan Jardine + * @summary + * @author [Allan Jardine](http://sprymedia.co.uk) * * @example * */ -$.fn.dataTableExt.oApi.fnVisibleToColumnIndex = function ( oSettings, iMatch ) +jQuery.fn.dataTableExt.oApi.fnVisibleToColumnIndex = function ( oSettings, iMatch ) { return oSettings.oApi._fnVisibleToColumnIndex( oSettings, iMatch ); }; diff --git a/api/page.jumpToData().js b/api/page.jumpToData().js new file mode 100644 index 0000000..49df017 --- /dev/null +++ b/api/page.jumpToData().js @@ -0,0 +1,20 @@ +/** + * Jump to data + * + * @name page.JumpToData() + * @summary + * @author [Allan Jardine](http://sprymedia.co.uk) + * @requires DataTables 1.10+ + * + * @example + * table.page.jumpToData( 0, "Allan Jardine" ); + */ + +jQuery.fn.dataTable.Api.register( 'page.jumpToData()', function ( column, data ) { + var pos = this.column(column, {order:'current'}).data().indexOf( data ); + + if ( pos >= 0 ) { + var page = Math.floor( pos / this.page.info().length ); + this.page( page ).draw( false ); + } +} ); \ No newline at end of file diff --git a/api/sum().js b/api/sum().js index 74c90f1..212ccbd 100644 --- a/api/sum().js +++ b/api/sum().js @@ -1,8 +1,9 @@ /** * Sum the values in a data set. + * * @name sum() - * @anchor sum() - * @author Allan Jardine + * @summary + * @author [Allan Jardine](http://sprymedia.co.uk) * @requires DataTables 1.10+ * * @example diff --git a/filtering/row-based/TableTools.ShowSelectedOnly.js b/filtering/row-based/TableTools.ShowSelectedOnly.js index 39812da..4a7b114 100644 --- a/filtering/row-based/TableTools.ShowSelectedOnly.js +++ b/filtering/row-based/TableTools.ShowSelectedOnly.js @@ -1,6 +1,11 @@ /** - * Used in combination with TableTools and selectable rows, this will allow you to switch between showing all rows and just the selected ones. - * @author Caleb Harrelson + * Used in combination with TableTools and selectable rows, this will allow you + * to switch between showing all rows and just the selected ones. + * + * @name Show selected only + * @summary Show only selected rows, or all rows, through filtering + * @requires TableTools + * @author [Caleb Harrelson](http://stackoverflow.com/users/8507/phloopy) * * @example * $('#example').dataTable({ @@ -74,9 +79,9 @@ if ($lengthSelect.length == 0) $lengthSelect = $('select :eq(0)', nLength); - /* - * Set the length to the current display length - thanks to Andrea Pavlovic for this fix, - * and Stefan Skopnik for fixing the fix! + /* + * Set the length to the current display length - thanks to Andrea Pavlovic for this fix, + * and Stefan Skopnik for fixing the fix! */ $lengthSelect.find('option[value="' + oSettings._iDisplayLength + '"]', nLength).attr("selected", true); diff --git a/filtering/row-based/range_dates.js b/filtering/row-based/range_dates.js index 4a28784..591b482 100644 --- a/filtering/row-based/range_dates.js +++ b/filtering/row-based/range_dates.js @@ -2,17 +2,18 @@ * Filter a column on a specific date range. Note that you will likely need * to change the id's on the inputs and the columns in which the start and * end date exist. - * @name Range filtering (dates) - * @anchor range_dates - * @author guillimon + * + * @name Date range filter + * @summary Filter the table based on two dates in different columns + * @author _guillimon_ * * @example * $(document).ready(function() { - * var oTable = $('#example').dataTable(); + * var table = $('#example').DataTable(); * * // Add event listeners to the two range filtering inputs - * $('#min').keyup( function() { oTable.fnDraw(); } ); - * $('#max').keyup( function() { oTable.fnDraw(); } ); + * $('#min').keyup( function() { table.draw(); } ); + * $('#max').keyup( function() { table.draw(); } ); * } ); */ @@ -22,22 +23,22 @@ $.fn.dataTableExt.afnFiltering.push( var iFfin = document.getElementById('ffin').value; var iStartDateCol = 6; var iEndDateCol = 7; - - iFini=iFini.substring(6,10) + iFini.substring(3,5)+ iFini.substring(0,2) - iFfin=iFfin.substring(6,10) + iFfin.substring(3,5)+ iFfin.substring(0,2) - + + iFini=iFini.substring(6,10) + iFini.substring(3,5)+ iFini.substring(0,2); + iFfin=iFfin.substring(6,10) + iFfin.substring(3,5)+ iFfin.substring(0,2); + var datofini=aData[iStartDateCol].substring(6,10) + aData[iStartDateCol].substring(3,5)+ aData[iStartDateCol].substring(0,2); var datoffin=aData[iEndDateCol].substring(6,10) + aData[iEndDateCol].substring(3,5)+ aData[iEndDateCol].substring(0,2); - - if ( iFini == "" && iFfin == "" ) + + if ( iFini === "" && iFfin === "" ) { return true; } - else if ( iFini <= datofini && iFfin == "") + else if ( iFini <= datofini && iFfin === "") { return true; } - else if ( iFfin >= datoffin && iFini == "") + else if ( iFfin >= datoffin && iFini === "") { return true; } @@ -46,5 +47,5 @@ $.fn.dataTableExt.afnFiltering.push( return true; } return false; - } + } ); diff --git a/filtering/row-based/range_numbers.js b/filtering/row-based/range_numbers.js index 9eb04f4..ca58575 100644 --- a/filtering/row-based/range_numbers.js +++ b/filtering/row-based/range_numbers.js @@ -2,18 +2,19 @@ * Filter a specific numeric column on the value being between two given * numbers. Note that you will likely need to change the id's on the inputs * and the column in which the numeric value is given. + * + * @summary Filter the data between two numbers (inclusive) * @name Range filtering (numbers) - * @anchor range_numbers - * @author Allan Jardine + * @author [Allan Jardine](http://sprymedia.co.uk) * * @example * $(document).ready(function() { * // Initialise datatables - * var oTable = $('#example').dataTable(); + * var table = $('#example').DataTable(); * * // Add event listeners to the two range filtering inputs - * $('#min').keyup( function() { oTable.fnDraw(); } ); - * $('#max').keyup( function() { oTable.fnDraw(); } ); + * $('#min').keyup( function() { table.draw(); } ); + * $('#max').keyup( function() { table.draw(); } ); * } ); */ @@ -22,17 +23,17 @@ jQuery.fn.dataTableExt.afnFiltering.push( var iColumn = 3; var iMin = document.getElementById('min').value * 1; var iMax = document.getElementById('max').value * 1; - + var iVersion = aData[iColumn] == "-" ? 0 : aData[iColumn]*1; - if ( iMin == "" && iMax == "" ) + if ( iMin === "" && iMax === "" ) { return true; } - else if ( iMin == "" && iVersion < iMax ) + else if ( iMin === "" && iVersion < iMax ) { return true; } - else if ( iMin < iVersion && "" == iMax ) + else if ( iMin < iVersion && "" === iMax ) { return true; } diff --git a/filtering/type-based/accent-neutralise.js b/filtering/type-based/accent-neutralise.js new file mode 100644 index 0000000..20fe11f --- /dev/null +++ b/filtering/type-based/accent-neutralise.js @@ -0,0 +1,56 @@ +/** + * When search a table with accented characters, it can be frustrating to have + * an input such as _Zurich_ not match _Zürich_ in the table (`u !== ü`). This + * type based search plug-in replaces the built-in string formatter in + * DataTables with a function that will remove replace the accented characters + * with their unaccented counterparts for fast and easy filtering. + * + * Note that with the accented characters being replaced, a search input using + * accented characters will no longer match. The second example below shows + * how the function can be used to remove accents from the search input as well, + * to mitigate this problem. + * + * @summary Replace accented characters with unaccented counterparts + * @name Accent neutralise + * @author Allan Jardine + * + * @example + * $(document).ready(function() { + * $('#example').dataTable(); + * } ); + * + * @example + * $(document).ready(function() { + * var table = $('#example').dataTable(); + * + * // Remove accented character from search input as well + * $('#myInput').keyup( function () { + * table + * .search( + * jQuery.fn.DataTable.ext.type.search.string( this ) + * ) + * .draw() + * } ); + * } ); + */ + +jQuery.fn.DataTable.ext.type.search.string = function ( data ) { + return ! data ? + '' : + typeof data === 'string' ? + data + .replace( /\n/g, ' ' ) + .replace( /á/g, 'a' ) + .replace( /é/g, 'e' ) + .replace( /í/g, 'i' ) + .replace( /ó/g, 'o' ) + .replace( /ú/g, 'u' ) + .replace( /ê/g, 'e' ) + .replace( /î/g, 'i' ) + .replace( /ô/g, 'o' ) + .replace( /è/g, 'e' ) + .replace( /ï/g, 'i' ) + .replace( /ü/g, 'u' ) + .replace( /ç/g, 'c' ) : + data; +}; diff --git a/filtering/type-based/html.js b/filtering/type-based/html.js index c2c886e..7fec55a 100644 --- a/filtering/type-based/html.js +++ b/filtering/type-based/html.js @@ -1,32 +1,38 @@ /** - * DataTables has a built in type called 'html' which will strip HTML tags + * DataTables has a built in type called `html` which will strip HTML tags * from a search string, but it doesn't cope with nested HTML inside another * element's attributes (for example DOM0 events with have HTML in them). This * plug-in function overrules the built-in method and provides complete HTML - * tag removal. Note that this function is not included in DataTables by + * tag removal. + * + * Note that this function is not included in DataTables by * default because it is slightly slower than the built-in method, which is * good enough for by far the majority of use cases. + * + * @summary Strip HTML using DOM methods * @name html - * @anchor html_column - * @author guillimon + * @author _guillimon_ * * @example * $(document).ready(function() { - * var oTable = $('#example').dataTable({ - * "aoColumns": [ - * "sType": "html", - * null + * $('#example').dataTable({ + * "columnDefs": [ + * { type: "html", target: 0 } * ] * }); * } ); */ -jQuery.fn.dataTableExt.ofnSearch['html'] = function ( sData ) { - var n = document.createElement('div'); - n.innerHTML = sData; - if ( n.textContent ) { - return n.textContent.replace(/\n/g," "); - } else { - return n.innerText.replace(/\n/g," "); - } +(function () { + +var _div = document.createElement('div'); + +jQuery.fn.dataTable.ext.type.search.html = function ( data ) { + _div.innerHTML = data; + + return _div.textContent ? + _div.textContent.replace(/\n/g," ") : + _div.innerText.replace(/\n/g," "); }; + +})(); diff --git a/filtering/type-based/phoneNumber.js b/filtering/type-based/phoneNumber.js new file mode 100644 index 0000000..ed1a20c --- /dev/null +++ b/filtering/type-based/phoneNumber.js @@ -0,0 +1,31 @@ +/** + * Telephone numbers are a common data point to display in HTML tables, and are + * often formatted (e.g. `dt-string 555-1234`). Typically, when searching a + * table a user would need to enter the number in exactly the same format it is + * displayed in, but this is not always convenient (e.g. you might search for + * `dt-string 5551`). + * + * This filtering plug-in will allow both forms to be matched be providing both + * the formatted and de-formatted data to the table's search. + * + * @summary Make phone numbers searchable formatted or unformatted + * @name Phone number + * @author Allan Jardine + * + * @example + * $(document).ready(function() { + * $('#example').dataTable( { + * columnDefs: [ + * { type: 'phoneNumber', target: 4 } + * ] + * } ); + * } ); + */ + +jQuery.fn.DataTable.ext.type.search.phoneNumber = function ( data ) { + return ! data ? + '' : + typeof data === 'string' ? + data + data.replace(/[ \-]/g, '') : + data; +}; diff --git a/pagination/ellipses.js b/pagination/ellipses.js index 1a3d225..8ad71cf 100644 --- a/pagination/ellipses.js +++ b/pagination/ellipses.js @@ -1,15 +1,23 @@ /* - * This plug-in adds another pagination option similar to full_numbers, - * except it adds ellipses around the page numbers when applicable. - * You can set how many page numbers should be displayed with the iShowPages option. - * This plug-in extends the oStdClasses object with the following properties: + * This plug-in adds another pagination option similar to `full_numbers`, except + * it adds ellipses around the page numbers when applicable. You can set how + * many page numbers should be displayed with the iShowPages option. + * + * This plug- in extends the oStdClasses object with the following properties: * sPageEllipsis, sPageNumber and sPageNumbers. + * * It also extends the oSettings object with the following properties: - * _iShowPages, _iShowPagesHalf, _iCurrentPage, _iTotalPages, _iFirstPage and _iLastPage. + * _iShowPages, _iShowPagesHalf, _iCurrentPage, _iTotalPages, _iFirstPage and + * _iLastPage. + * + * Note that DataTables 1.10 has this ability built in. As such, this plug-ins + * has been marked as depreciated, but may still be useful for if you are using + * an old version of DataTables. * * @name Ellipses - * @anchor ellipses - * @author Dave Kennedy + * @summary Show ellipses in the pagination control where there is a gap in numbers + * @depreciated + * @author [Dave Kennedy](http://daveden.wordpress.com/) * @example * $(document).ready(function() { * $('#example').dataTable({ diff --git a/pagination/extjs.js b/pagination/extjs.js index c68f438..86b1e1b 100644 --- a/pagination/extjs.js +++ b/pagination/extjs.js @@ -1,9 +1,10 @@ /** * 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 - * @anchor extjs - * @author Zach Curtis + * @summary Pagination in the styling of ExtJS + * @author [Zach Curtis](http://zachariahtimothy.wordpress.com/) * * @example * $(document).ready(function() { diff --git a/pagination/four_button.js b/pagination/four_button.js index eb61e33..db59afa 100644 --- a/pagination/four_button.js +++ b/pagination/four_button.js @@ -1,10 +1,17 @@ /** * 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. + * plug-in meets the two in the middle providing navigation controls for + * forward, back, first and last. + * + * DataTables has this ability built in using the `dt-string full` option of + * the `dt-init pagingType` initialisation option. As such, this plug-in is + * marked as depreciated. + * * @name Four button navigation - * @anchor four_button - * @author Allan Jardine + * @summary Display forward, back, first and last buttons. + * @depreciated + * @author [Allan Jardine](http://sprymedia.co.uk) * * @example * $(document).ready(function() { @@ -17,61 +24,61 @@ $.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' ); - + var nFirst = document.createElement( 'span' ); + var nPrevious = document.createElement( 'span' ); + var nNext = document.createElement( 'span' ); + var 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 ; iAllan Jardine + * @summary Shows an input element into which the user can type a page number + * @author [Allan Jardine](http://sprymedia.co.uk) * * @example * $(document).ready(function() { @@ -26,19 +27,19 @@ $.fn.dataTableExt.oPagination.input = { 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' ); @@ -47,12 +48,12 @@ $.fn.dataTableExt.oPagination.input = { 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 ); @@ -60,29 +61,28 @@ $.fn.dataTableExt.oPagination.input = { 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++; @@ -91,33 +91,33 @@ $.fn.dataTableExt.oPagination.input = { { this.value--; } - - if ( this.value == "" || this.value.match(/[^0-9]/) ) + + 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._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 ) @@ -126,14 +126,14 @@ $.fn.dataTableExt.oPagination.input = { } 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 ; iAllan Jardine + * @summary Show page changes as a redraw of the table, scrolling records. + * @author [Allan Jardine](http://sprymedia.co.uk) * * @example * $(document).ready(function() { @@ -18,7 +19,7 @@ /* Time between each scrolling frame */ $.fn.dataTableExt.oPagination.iTweenTime = 100; - + $.fn.dataTableExt.oPagination.scrolling = { "fnInit": function ( oSettings, nPaging, fnCallbackDraw ) { @@ -30,7 +31,7 @@ $.fn.dataTableExt.oPagination.scrolling = { fnCallbackDraw( oSettings ); } }; - + var sAppend = (!oSettings.bJUI) ? ''+oLang.sPrevious+''+ ''+oLang.sNext+'' @@ -38,27 +39,27 @@ $.fn.dataTableExt.oPagination.scrolling = { ''+ ''; $(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; + oSettings.iPagingEnd = 0; } - + var iTween = $.fn.dataTableExt.oPagination.iTweenTime; var innerLoop = function () { if ( oSettings.iPagingLoopStart > oSettings.iPagingEnd ) { @@ -72,22 +73,22 @@ $.fn.dataTableExt.oPagination.scrolling = { }; 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 ) { @@ -102,26 +103,26 @@ $.fn.dataTableExt.oPagination.scrolling = { 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 ; ijneilliii + * @summary Show a `dt-tag select` list of pages the user can pick from. + * @author _jneilliii_ * * @example * $(document).ready(function() { diff --git a/sorting/alt-string.js b/sorting/alt-string.js index e9078c6..88ba085 100644 --- a/sorting/alt-string.js +++ b/sorting/alt-string.js @@ -2,16 +2,24 @@ * Sort on the 'alt' tag of images in a column. This is particularly useful if * you have a column of images (ticks and crosses for example) and you want to * control the sorting using the alt tag. + * * @name Alt string - * @anchor alt - * @author Jumpy + * @summary Use the `alt` attribute of an image tag as the data to sort upon. + * @author _Jumpy_ + * + * @example + * $('#example').dataTable( { + * columnDefs: [ + * { type: 'alt-string', targets: 0 } + * ] + * } ); */ jQuery.extend( jQuery.fn.dataTableExt.oSort, { "alt-string-pre": function ( a ) { return a.match(/alt="(.*?)"/)[1].toLowerCase(); }, - + "alt-string-asc": function( a, b ) { return ((a < b) ? -1 : ((a > b) ? 1 : 0)); }, diff --git a/sorting/anti-the.js b/sorting/anti-the.js index 6b264d1..a6f2468 100644 --- a/sorting/anti-the.js +++ b/sorting/anti-the.js @@ -3,9 +3,17 @@ * the word "the" at the start of some individual titles, which you don't want * to include in your sorting order. This plug-in will strip the word "the" * from the start of a string and sort on what is left. + * * @name Anti-"the" - * @anchor anti_the - * @author Allan Jardine + * @summary Sort with the prefixed word `dt-string The` removed, if present + * @author [Allan Jardine](http://sprymedia.co.uk) + * + * @example + * $('#example').dataTable( { + * columnDefs: [ + * { type: 'anti-the', targets: 0 } + * ] + * } ); */ jQuery.extend( jQuery.fn.dataTableExt.oSort, { diff --git a/sorting/chinese-string.js b/sorting/chinese-string.js index a379ec9..5b0baf8 100644 --- a/sorting/chinese-string.js +++ b/sorting/chinese-string.js @@ -1,17 +1,29 @@ /** - * Sorting in Javascript for Chinese Character. The Chinese Characters are sorted on the radical and number of - * strokes. This plug-in performs sorting for Chinese characters. - * localeCompare MDC documentation. - * Please also see note about localeCompare and IE9. + * Sorting in Javascript for Chinese Character. The Chinese Characters are + * sorted on the radical and number of strokes. This plug-in performs sorting + * for Chinese characters using the Javascript [localeCompare](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/localeCompare) + * function. + * + * Please note that `localeCompare` is not implemented in the same way in all + * browsers, potentially leading to different results (particularly in IE). + * * @name Chinese (string) - * @anchor chinese-string - * @author Patrik Lindstr�m + * @summary Sort Chinese characters + * @author [Patrik Lindström](http://www.lcube.se/sorting-chinese-characters-in-javascript/) + * + * @example + * $('#example').dataTable( { + * columnDefs: [ + * { type: 'chinese-string', targets: 0 } + * ] + * } ); */ - - jQuery.extend( jQuery.fn.dataTableExt.oSort, { + +jQuery.extend( jQuery.fn.dataTableExt.oSort, { "chinese-string-asc" : function (s1, s2) { return s1.localeCompare(s2); }, + "chinese-string-desc" : function (s1, s2) { return s2.localeCompare(s1); } diff --git a/sorting/currency.js b/sorting/currency.js index a1decbd..a8072ab 100644 --- a/sorting/currency.js +++ b/sorting/currency.js @@ -2,9 +2,22 @@ * This plug-in will provide numeric sorting for currency columns (either * detected automatically with the currency type detection plug-in or set * manually) while taking account of the currency symbol ($ or £ by default). + * + * DataTables 1.10+ has currency sorting abilities built-in and will be + * automatically detected. As such this plug-in is marked as depreciated, but + * might be useful when working with old versions of DataTables. + * * @name Currency - * @anchor currency - * @author Allan Jardine + * @summary Sort data numerically when it has a leading currency symbol. + * @depreciated + * @author [Allan Jardine](http://sprymedia.co.uk) + * + * @example + * $('#example').dataTable( { + * columnDefs: [ + * { type: 'currency', targets: 0 } + * ] + * } ); */ jQuery.extend( jQuery.fn.dataTableExt.oSort, { diff --git a/sorting/custom-data-source/dom-checkbox.js b/sorting/custom-data-source/dom-checkbox.js index 8b47afe..7d44d5c 100644 --- a/sorting/custom-data-source/dom-checkbox.js +++ b/sorting/custom-data-source/dom-checkbox.js @@ -1,15 +1,15 @@ /** * Read information from a column of checkboxes (input elements with type * checkbox) and return an array to use as a basis for sorting. + * + * @summary Sort based on the checked state of checkboxes in a column * @name Checkbox data source - * @author Allan Jardine + * @author [Allan Jardine](http://sprymedia.co.uk) */ -$.fn.dataTableExt.afnSortData['dom-checkbox'] = function ( oSettings, iColumn ) +$.fn.dataTable.ext.order['dom-checkbox'] = function ( settings, col ) { - var aData = []; - $( 'td:eq('+iColumn+') input', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () { - aData.push( this.checked==true ? "1" : "0" ); + return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) { + return $('input', td).prop('checked') ? '1' : '0'; } ); - return aData; }; diff --git a/sorting/custom-data-source/dom-select.js b/sorting/custom-data-source/dom-select.js index 87048e6..22774e3 100644 --- a/sorting/custom-data-source/dom-select.js +++ b/sorting/custom-data-source/dom-select.js @@ -1,15 +1,16 @@ /** * Read information from a column of select (drop down) menus and return an * array to use as a basis for sorting. + * + * @summary Sort based on the value of the `dt-tag select` options in a column * @name Select menu data source - * @author Allan Jardine + * @requires DataTables 1.10+ + * @author [Allan Jardine](http://sprymedia.co.uk) */ -$.fn.dataTableExt.afnSortData['dom-select'] = function ( oSettings, iColumn ) +$.fn.dataTable.ext.order['dom-select'] = function ( settings, col ) { - var aData = []; - $( 'td:eq('+iColumn+') select', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () { - aData.push( $(this).val() ); + return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) { + return $('select', td).val(); } ); - return aData; }; diff --git a/sorting/custom-data-source/dom-text.js b/sorting/custom-data-source/dom-text.js index 4e42d80..fc0c4b5 100644 --- a/sorting/custom-data-source/dom-text.js +++ b/sorting/custom-data-source/dom-text.js @@ -1,15 +1,16 @@ /** * Read information from a column of input (type text) elements and return an * array to use as a basis for sorting. + * + * @summary Sorting based on the values of `dt-tag input` elements in a column. * @name Input element data source - * @author Allan Jardine + * @requires DataTables 1.10+ + * @author [Allan Jardine](http://sprymedia.co.uk) */ -$.fn.dataTableExt.afnSortData['dom-text'] = function ( oSettings, iColumn ) +$.fn.dataTable.ext.order['dom-text'] = function ( settings, col ) { - var aData = []; - $( 'td:eq('+iColumn+') input', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () { - aData.push( this.value ); + return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) { + return $('input', td).val(); } ); - return aData; }; diff --git a/sorting/date-dd-MMM-yyyy.js b/sorting/date-dd-MMM-yyyy.js index 6e6810f..7d6758f 100644 --- a/sorting/date-dd-MMM-yyyy.js +++ b/sorting/date-dd-MMM-yyyy.js @@ -1,18 +1,26 @@ /* - * Adds a new sorting option to dataTables called date-dd-mmm-yyyy. Also + * Adds a new sorting option to dataTables called `date-dd-mmm-yyyy`. Also * includes a type detection plug-in. Matches and sorts date strings in - * the format: (dd/mmm/yyyy. For example: - *
    - *
  • 02-FEB-1978
  • - *
  • 17-MAY-2013
  • - *
  • 31-JAN-2014
  • - *
+ * the format: `dd/mmm/yyyy`. For example: + * + * * 02-FEB-1978 + * * 17-MAY-2013 + * * 31-JAN-2014 * - * @name Date dd-mmm-yyyy - * @anchor date-dd-mmm-yyyy - * @author Jeromy French + * @name Date (dd-mmm-yyyy) + * @summary Sort dates in the format `dd-mmm-yyyy` + * @author [Jeromy French](http://www.appliedinter.net/jeromy_works/) + * + * @example + * $('#example').dataTable( { + * columnDefs: [ + * { type: 'date-dd-mmm-yyyy', targets: 0 } + * ] + * } ); */ +(function () { + var customDateDDMMMYYYYToOrd = function (date) { "use strict"; //let's avoid tom-foolery in this function // Convert to a number YYYYMMDD which we can use to order @@ -20,7 +28,8 @@ var customDateDDMMMYYYYToOrd = function (date) { return (dateParts[2] * 10000) + ($.inArray(dateParts[1].toUpperCase(), ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"]) * 100) + dateParts[0]; }; -// This will help DataTables magic detect the "dd-MMM-yyyy" format; Unshift so that it's the first data type (so it takes priority over existing) +// This will help DataTables magic detect the "dd-MMM-yyyy" format; Unshift +// so that it's the first data type (so it takes priority over existing) jQuery.fn.dataTableExt.aTypes.unshift( function (sData) { "use strict"; //let's avoid tom-foolery in this function @@ -44,4 +53,6 @@ jQuery.fn.dataTableExt.oSort['date-dd-mmm-yyyy-desc'] = function (a, b) { var ordA = customDateDDMMMYYYYToOrd(a), ordB = customDateDDMMMYYYYToOrd(b); return (ordA < ordB) ? 1 : ((ordA > ordB) ? -1 : 0); -}; \ No newline at end of file +}; + +})(); diff --git a/sorting/date-de.js b/sorting/date-de.js new file mode 100644 index 0000000..7e8131c --- /dev/null +++ b/sorting/date-de.js @@ -0,0 +1,64 @@ +/** + * This sorting plug-in for DataTables will correctly sort data in date time + * format typically used in Germany - `dd.mm.YYYY HH:mm`. + * + * @name Date / time (dd.mm.YYYY HH:mm) + * @summary Sort date / time in the format `dd.mm.YYYY HH:mm`. + * @author [Ronny Vedrilla](http://www.ambient-innovation.com) + * + * @example + * $('#example').dataTable( { + * columnDefs: [ + * { type: 'de_datetime', targets: 0 } + * ] + * } ); + */ + + jQuery.extend( jQuery.fn.dataTableExt.oSort, { + "de_datetime-asc": function ( a, b ) { + var x, y; + if ($.trim(a) !== '') { + var deDatea = $.trim(a).split(' '); + var deTimea = deDatea[1].split(':'); + var deDatea2 = deDatea[0].split('.'); + x = (deDatea2[2] + deDatea2[1] + deDatea2[0] + deTimea[0] + deTimea[1]) * 1; + } else { + x = Infinity; // = l'an 1000 ... + } + + if ($.trim(b) !== '') { + var deDateb = $.trim(b).split(' '); + var deTimeb = deDateb[1].split(':'); + deDateb = deDateb[0].split('.'); + y = (deDateb[2] + deDateb[1] + deDateb[0] + deTimeb[0] + deTimeb[1]) * 1; + } else { + y = Infinity; + } + var z = ((x < y) ? -1 : ((x > y) ? 1 : 0)); + return z; + }, + + "de_datetime-desc": function ( a, b ) { + var x, y; + if ($.trim(a) !== '') { + var deDatea = $.trim(a).split(' '); + var deTimea = deDatea[1].split(':'); + var deDatea2 = deDatea[0].split('.'); + x = (deDatea2[2] + deDatea2[1] + deDatea2[0] + deTimea[0] + deTimea[1]) * 1; + } else { + x = Infinity; + } + + if ($.trim(b) !== '') { + var deDateb = $.trim(b).split(' '); + var deTimeb = deDateb[1].split(':'); + deDateb = deDateb[0].split('.'); + y = (deDateb[2] + deDateb[1] + deDateb[0] + deTimeb[0] + deTimeb[1]) * 1; + } else { + y = Infinity; + } + var z = ((x < y) ? 1 : ((x > y) ? -1 : 0)); + return z; + } +} ); + diff --git a/sorting/date-eu.js b/sorting/date-eu.js index 5de6969..1f9c280 100644 --- a/sorting/date-eu.js +++ b/sorting/date-eu.js @@ -2,42 +2,51 @@ * Similar to the Date (dd/mm/YY) data sorting plug-in, this plug-in offers * additional flexibility with support for spaces between the values and * either . or / notation for the separators. + * * @name Date (dd . mm[ . YYYY]) - * @anchor date_eu - * @author Robert Sedovšek + * @summary Sort dates in the format `dd/mm/YY[YY]` (with optional spaces) + * @author [Robert Sedovšek](http://galjot.si/) + * + * @example + * $('#example').dataTable( { + * columnDefs: [ + * { type: 'date-eu', targets: 0 } + * ] + * } ); */ jQuery.extend( jQuery.fn.dataTableExt.oSort, { "date-eu-pre": function ( date ) { - var date = date.replace(" ", ""); - + date = date.replace(" ", ""); + var eu_date, year; + if (date.indexOf('.') > 0) { /*date a, format dd.mn.(yyyy) ; (year is optional)*/ - var eu_date = date.split('.'); + eu_date = date.split('.'); } else { /*date a, format dd/mn/(yyyy) ; (year is optional)*/ - var eu_date = date.split('/'); + eu_date = date.split('/'); } - + /*year (optional)*/ if (eu_date[2]) { - var year = eu_date[2]; + year = eu_date[2]; } else { - var year = 0; + year = 0; } - + /*month*/ var month = eu_date[1]; if (month.length == 1) { month = 0+month; } - + /*day*/ var day = eu_date[0]; if (day.length == 1) { day = 0+day; } - + return (year + month + day) * 1; }, diff --git a/sorting/date-euro.js b/sorting/date-euro.js index 509566c..6ac5ae6 100644 --- a/sorting/date-euro.js +++ b/sorting/date-euro.js @@ -3,22 +3,33 @@ * formatting, which is common in France and other European countries. It can * also be quickly adapted for other formatting as required. Furthermore, this * date sorting plug-in allows for empty values in the column. + * * @name Date (dd/mm/YYY hh:ii:ss) - * @anchor date_euro - * @author Ronan Guilloux + * @summary Sort date / time in the format `dd/mm/YYY hh:ii:ss` + * @author [Ronan Guilloux](http://coolforest.net/) + * + * @example + * $('#example').dataTable( { + * columnDefs: [ + * { type: 'date-euro', targets: 0 } + * ] + * } ); */ jQuery.extend( jQuery.fn.dataTableExt.oSort, { "date-euro-pre": function ( a ) { - if ($.trim(a) != '') { + var x; + + if ( $.trim(a) !== '' ) { var frDatea = $.trim(a).split(' '); var frTimea = frDatea[1].split(':'); var frDatea2 = frDatea[0].split('/'); - var x = (frDatea2[2] + frDatea2[1] + frDatea2[0] + frTimea[0] + frTimea[1] + frTimea[2]) * 1; - } else { - var x = 10000000000000; // = l'an 1000 ... + x = (frDatea2[2] + frDatea2[1] + frDatea2[0] + frTimea[0] + frTimea[1] + frTimea[2]) * 1; + } + else { + x = Infinity; } - + return x; }, diff --git a/sorting/date-uk.js b/sorting/date-uk.js index 26fbc4f..9d710d3 100644 --- a/sorting/date-uk.js +++ b/sorting/date-uk.js @@ -1,13 +1,21 @@ /** - * DataTables internal date sorting replies on Date.parse() which is part of + * DataTables internal date sorting replies on `Date.parse()` which is part of * the Javascript language, but you may wish to sort on dates which is doesn't * recognise. The following is a plug-in for sorting dates in the format - * dd/mm/yy. + * `dd/mm/yy`. * * An automatic type detection plug-in is available for this sorting plug-in. + * * @name Date (dd/mm/YY) - * @anchor date_uk + * @summary Sort dates in the format `dd/mm/YY` * @author Andy McMaster + * + * @example + * $('#example').dataTable( { + * columnDefs: [ + * { type: 'date-uk', targets: 0 } + * ] + * } ); */ jQuery.extend( jQuery.fn.dataTableExt.oSort, { diff --git a/sorting/datetime-us.js b/sorting/datetime-us.js index 0627fc5..7a59673 100644 --- a/sorting/datetime-us.js +++ b/sorting/datetime-us.js @@ -1,59 +1,81 @@ /* - * Adds a new sorting option to dataTables called datetime-us. Also - * includes a type detection plug-in. Matches and sorts date / time strings in - * the format: (m)m/(d)d/(yy)yy (h)h/m(m) (am|pm). For example: - *
    - *
  • 1/1/13 1:4 pm
  • - *
  • 01/01/2013 01:04 PM
  • - *
  • 1/1/2013 1:04 Pm
  • - *
+ * Adds a new sorting option to dataTables called `datetime-us`. + * + * Also included is a type detection plug-in. Matches and sorts date / time + * strings in the format: `(m)m/(d)d/(yy)yy (h)h/m(m) (am|pm)`. For example: + * + * * 1/1/13 1:4 pm + * * 01/01/2013 01:04 PM + * * 1/1/2013 1:04 Pm * * @name Date / time - US - * @anchor datetime_us - * @author Kevin Gravier -*/ -jQuery.extend( jQuery.fn.dataTableExt.oSort, { - "datetime-us-pre": function ( a ) { - var b = a.match(/(\d{1,2})\/(\d{1,2})\/(\d{2,4}) (\d{1,2}):(\d{1,2}) (am|pm|AM|PM|Am|Pm)/), - month = b[1], - day = b[2], - year = b[3], - hour = b[4], - min = b[5], - ap = b[6]; + * @summary Sort date / time in the format `m/d/yy h:m am|pm` + * @author [Kevin Gravier](http://mrkmg.com/) + * + * @example + * $('#example').dataTable( { + * columnDefs: [ + * { type: 'datetime-us', targets: 0 } + * ] + * } ); +*/ +jQuery.extend(jQuery.fn.dataTableExt.oSort, { + "datetime-us-pre": function (a) { + var b = a.match(/(\d{1,2})\/(\d{1,2})\/(\d{2,4}) (\d{1,2}):(\d{1,2}) (am|pm|AM|PM|Am|Pm)/), + month = b[1], + day = b[2], + year = b[3], + hour = b[4], + min = b[5], + ap = b[6]; + + if (hour == '12') { + hour = '0'; + if (ap == 'pm') { + hour = parseInt(hour, 10) + 12; + } - if(hour == '12') hour = '0'; - if(ap == 'pm') hour = parseInt(hour, 10)+12; + if (year.length == 2) { + if (parseInt(year, 10) < 70) { + year = '20' + year; + } + else { + year = '19' + year; + } + } + if (month.length == 1) { + month = '0' + month; + } + if (day.length == 1) { + day = '0' + day; + } + if (hour.length == 1) { + hour = '0' + hour; + } + if (min.length == 1) { + min = '0' + min; + } - if(year.length == 2){ - if(parseInt(year, 10)<70) year = '20'+year; - else year = '19'+year; - } - if(month.length == 1) month = '0'+month; - if(day.length == 1) day = '0'+day; - if(hour.length == 1) hour = '0'+hour; - if(min.length == 1) min = '0'+min; + var tt = year + month + day + hour + min; + return tt; + } + }, - var tt = year+month+day+hour+min; - return tt; - }, - "datetime-us-asc": function ( a, b ) { - return a - b; - }, + "datetime-us-asc": function (a, b) { + return a - b; + }, - "datetime-us-desc": function ( a, b ) { - return b - a; - } + "datetime-us-desc": function (a, b) { + return b - a; + } }); jQuery.fn.dataTableExt.aTypes.unshift( - function ( sData ) - { - if (sData !== null && sData.match(/\d{1,2}\/\d{1,2}\/\d{2,4} \d{1,2}:\d{1,2} (am|pm|AM|PM|Am|Pm)/)) - { + function (sData) { + if (sData !== null && sData.match(/\d{1,2}\/\d{1,2}\/\d{2,4} \d{1,2}:\d{1,2} (am|pm|AM|PM|Am|Pm)/)) { - return 'datetime-us'; - } - return null; - } + return 'datetime-us'; + } + return null; + } ); diff --git a/sorting/enum.js b/sorting/enum.js index eaafca7..1154616 100644 --- a/sorting/enum.js +++ b/sorting/enum.js @@ -1,11 +1,19 @@ /** - * Sort by priority through an enumerated list. In this case the words 'High', - * 'Medium' and 'Low' are used and thus sorted in priority order. This works + * Sort by priority through an enumerated list. In this case the words _High_, + * _Medium_ and _Low_ are used and thus sorted in priority order. This works * by converting the works to a numerical value and then sorting based on that * value. + * * @name enum - * @anchor enum - * @author Allan Jardine + * @summary Sort an enumerated list of options + * @author [Allan Jardine](http://sprymedia.co.uk) + * + * @example + * $('#example').dataTable( { + * columnDefs: [ + * { type: 'enum', targets: 0 } + * ] + * } ); */ jQuery.extend( jQuery.fn.dataTableExt.oSort, { diff --git a/sorting/file-size.js b/sorting/file-size.js index ea5f4f2..f36c246 100644 --- a/sorting/file-size.js +++ b/sorting/file-size.js @@ -4,18 +4,26 @@ * magnitude of the file size. This plug-in allows sorting to take these * indicates of size into account. A counterpart type detection plug-in * is also available. + * * @name File size - * @anchor file_size - * @author anjibman + * @summary Sort abbreviated file sizes correctly (8MB, 4KB etc) + * @author _anjibman_ + * + * @example + * $('#example').dataTable( { + * columnDefs: [ + * { type: 'file-size', targets: 0 } + * ] + * } ); */ jQuery.extend( jQuery.fn.dataTableExt.oSort, { "file-size-pre": function ( a ) { var x = a.substring(0,a.length - 2); - - var x_unit = (a.substring(a.length - 2, a.length) == "MB" ? + + var x_unit = (a.substring(a.length - 2, a.length) == "MB" ? 1000 : (a.substring(a.length - 2, a.length) == "GB" ? 1000000 : 1)); - + return parseInt( x * x_unit, 10 ); }, diff --git a/sorting/formatted-numbers.js b/sorting/formatted-numbers.js index fc6bd43..a534ffa 100644 --- a/sorting/formatted-numbers.js +++ b/sorting/formatted-numbers.js @@ -1,10 +1,23 @@ /** - * This plug-in will provide numeric sorting for numeric columns which have extra - * formatting, such as thousands seperators, currency symobols or any other + * This plug-in will provide numeric sorting for numeric columns which have + * extra formatting, such as thousands separators, currency symbols or any other * non-numeric data. + * + * DataTables 1.10+ has formatted number detection and sorting abilities built- + * in. As such this plug-in is marked as depreciated, but might be useful when + * working with old versions of DataTables. + * * @name Formatted numbers - * @anchor formatted_numbers - * @author Allan Jardine + * @summary Sort numbers which are displayed with thousand separators + * @depreciated + * @author [Allan Jardine](http://sprymedia.co.uk) + * + * @example + * $('#example').dataTable( { + * columnDefs: [ + * { type: 'formatted-num', targets: 0 } + * ] + * } ); */ jQuery.extend( jQuery.fn.dataTableExt.oSort, { diff --git a/sorting/ip-address.js b/sorting/ip-address.js index 29d72a2..7ea648a 100644 --- a/sorting/ip-address.js +++ b/sorting/ip-address.js @@ -3,9 +3,17 @@ * be most useful when using DataTables for a networking application, and * reporting information containing IP address. Also has a matching type * detection plug-in for automatic type detection. + * * @name IP addresses - * @anchor ip_address + * @summary Sort IP addresses numerically * @author Brad Wasson + * + * @example + * $('#example').dataTable( { + * columnDefs: [ + * { type: 'ip-address', targets: 0 } + * ] + * } ); */ jQuery.extend( jQuery.fn.dataTableExt.oSort, { diff --git a/sorting/monthYear.js b/sorting/monthYear.js index 63f2e6f..8668e08 100644 --- a/sorting/monthYear.js +++ b/sorting/monthYear.js @@ -1,9 +1,17 @@ /** * This sorting plug-in will sort, in calendar order, data which * is in the format "MM YY". - * @name Month / year sorting - * @anchor monthYear + * + * @name Date (MM YY) + * @anchor Sort dates in the format `MM YY` * @author Michael Motek + * + * @example + * $('#example').dataTable( { + * columnDefs: [ + * { type: 'monthYear', targets: 0 } + * ] + * } ); */ jQuery.extend( jQuery.fn.dataTableExt.oSort, { diff --git a/sorting/natural.js b/sorting/natural.js index ea91b43..5cc5e26 100644 --- a/sorting/natural.js +++ b/sorting/natural.js @@ -1,13 +1,22 @@ /** * Data can often be a complicated mix of numbers and letters (file names * are a common example) and sorting them in a natural manner is quite a - * difficult problem. Fortunately a deal of work has already been done in - * this area by other authors - the following plug-in uses the naturalSort() - * function by Jim Palmer (download it here) - * to provide natural sorting in DataTables. + * difficult problem. + * + * Fortunately a deal of work has already been done in this area by other + * authors - the following plug-in uses the [naturalSort() function by Jim + * Palmer](http://www.overset.com/2008/09/01/javascript-natural-sort-algorithm-with-unicode-support) to provide natural sorting in DataTables. + * * @name Natural sorting - * @anchor natrual - * @author Jim Palmer + * @summary Sort data with a mix of numbers and letters _naturally_. + * @author [Jim Palmer](http://www.overset.com/2008/09/01/javascript-natural-sort-algorithm-with-unicode-support) + * + * @example + * $('#example').dataTable( { + * columnDefs: [ + * { type: 'natural', targets: 0 } + * ] + * } ); */ (function() { @@ -31,26 +40,39 @@ function naturalSort (a, b) { xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'), yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'), // numeric, hex or date detection - xD = parseInt(x.match(hre)) || (xN.length != 1 && x.match(dre) && Date.parse(x)), - yD = parseInt(y.match(hre)) || xD && y.match(dre) && Date.parse(y) || null; + xD = parseInt(x.match(hre), 10) || (xN.length != 1 && x.match(dre) && Date.parse(x)), + yD = parseInt(y.match(hre), 10) || xD && y.match(dre) && Date.parse(y) || null; + // first try and sort Hex codes or Dates - if (yD) - if ( xD < yD ) return -1; - else if ( xD > yD ) return 1; + if (yD) { + if ( xD < yD ) { + return -1; + } + else if ( xD > yD ) { + return 1; + } + } + // natural sorting through split numeric strings and default strings for(var cLoc=0, numS=Math.max(xN.length, yN.length); cLoc < numS; cLoc++) { // find floats not starting with '0', string or 0 if not defined (Clint Priest) - var oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0; - var oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0; + var oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc], 10) || xN[cLoc] || 0; + var oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc], 10) || yN[cLoc] || 0; // handle numeric vs string comparison - number < string - (Kyle Adams) - if (isNaN(oFxNcL) !== isNaN(oFyNcL)) return (isNaN(oFxNcL)) ? 1 : -1; + if (isNaN(oFxNcL) !== isNaN(oFyNcL)) { + return (isNaN(oFxNcL)) ? 1 : -1; + } // rely on string comparison if different types - i.e. '02' < 2 != '02' < '2' else if (typeof oFxNcL !== typeof oFyNcL) { - oFxNcL += ''; - oFyNcL += ''; + oFxNcL += ''; + oFyNcL += ''; + } + if (oFxNcL < oFyNcL) { + return -1; + } + if (oFxNcL > oFyNcL) { + return 1; } - if (oFxNcL < oFyNcL) return -1; - if (oFxNcL > oFyNcL) return 1; } return 0; } diff --git a/sorting/num-html.js b/sorting/num-html.js index 7783a3d..2d31b36 100644 --- a/sorting/num-html.js +++ b/sorting/num-html.js @@ -4,9 +4,22 @@ * strips the HTML and then sorts by numbers. Note also that this sorting * plug-in has an equivalent type detection plug-in which can make integration * easier. + * + * DataTables 1.10+ has HTML numeric data type detection and sorting abilities + * built-in. As such this plug-in is marked as depreciated, but might be useful + * when working with old versions of DataTables. + * * @name Numbers with HTML - * @anchor numbers_html - * @author Allan Jardine + * @summary Sort data which is a mix of HTML and numeric data. + * @depreciated + * @author [Allan Jardine](http://sprymedia.co.uk) + * + * @example + * $('#example').dataTable( { + * columnDefs: [ + * { type: 'num-html', targets: 0 } + * ] + * } ); */ jQuery.extend( jQuery.fn.dataTableExt.oSort, { diff --git a/sorting/numeric-comma.js b/sorting/numeric-comma.js index 5e5cb27..27248e4 100644 --- a/sorting/numeric-comma.js +++ b/sorting/numeric-comma.js @@ -1,15 +1,24 @@ /** * It is not uncommon for non-English speaking countries to use a comma for a * decimal place. This sorting plug-in shows how that can be taken account of in - * sorting by adding the type 'numeric-comma' to DataTables. A type detection + * sorting by adding the type `numeric-comma` to DataTables. A type detection * plug-in for this sorting method is provided below. * * Please note that the 'Formatted numbers' type detection and sorting plug-ins * offer greater flexibility that this plug-in and should be used in preference * to this method. + * * @name Commas for decimal place - * @anchor numeric_comma - * @author Allan Jardine + * @summary Sort numbers correctly which use a common as the decimal place. + * @depreciated + * @author [Allan Jardine](http://sprymedia.co.uk) + * + * @example + * $('#example').dataTable( { + * columnDefs: [ + * { type: 'numeric-comma', targets: 0 } + * ] + * } ); */ jQuery.extend( jQuery.fn.dataTableExt.oSort, { diff --git a/sorting/percent.js b/sorting/percent.js index 9d154c0..05e5f1d 100644 --- a/sorting/percent.js +++ b/sorting/percent.js @@ -1,8 +1,21 @@ /** * Sort numeric data which has a percent sign with it. + * + * DataTables 1.10+ has percentage data type detection and sorting abilities + * built-in. As such this plug-in is marked as depreciated, but might be useful + * when working with old versions of DataTables. + * * @name Percentage - * @anchor percentage - * @author Jonathan Romley + * @summary Sort numeric data with a postfixed percentage symbol + * @depreciated + * @author [Jonathan Romley](http://jonathanromley.org/) + * + * @example + * $('#example').dataTable( { + * columnDefs: [ + * { type: 'percent', targets: 0 } + * ] + * } ); */ jQuery.extend( jQuery.fn.dataTableExt.oSort, { diff --git a/sorting/persian.js b/sorting/persian.js index 2b147a5..a6ea68e 100644 --- a/sorting/persian.js +++ b/sorting/persian.js @@ -2,35 +2,45 @@ * Sorting in Javascript can be difficult to get right with non-Roman * characters - for which special consideration must be made. This plug-in * performs correct sorting on Persian characters. + * * @name Persian - * @anchor Persian - * @author Afshin Mehrabani + * @summary Sort Persian strings alphabetically + * @author [Afshin Mehrabani](http://www.afshinblog.com/) + * + * @example + * $('#example').dataTable( { + * columnDefs: [ + * { type: 'pstring', targets: 0 } + * ] + * } ); */ (function(){ -var persianSort = [ 'آ', 'ا', 'ب', 'پ', 'ت', 'ث', 'ج', 'چ', 'ح', 'خ', 'د', 'ذ', 'ر', 'ز', 'ژ', +var persianSort = [ 'آ', 'ا', 'ب', 'پ', 'ت', 'ث', 'ج', 'چ', 'ح', 'خ', 'د', 'ذ', 'ر', 'ز', 'ژ', 'س', 'ش', 'ص', 'ط', 'ظ', 'ع', 'غ', 'ف', 'ق', 'ک', 'گ', 'ل', 'م', 'ن', 'و', 'ه', 'ی', 'ي' ]; function GetUniCode(source) { source = $.trim(source); - result = ''; + var result = ''; + var i, index; for (i = 0; i < source.length; i++) { //Check and fix IE indexOf bug if (!Array.indexOf) { - var index = jQuery.inArray(source.charAt(i), persianSort); + index = jQuery.inArray(source.charAt(i), persianSort); }else{ - var index = persianSort.indexOf(source.charAt(i)); + index = persianSort.indexOf(source.charAt(i)); } if (index < 0) { index = source.charCodeAt(i); } - if (index < 10) + if (index < 10) { index = '0' + index; + } result += '00' + index; } return 'a' + result; -}; +} jQuery.extend( jQuery.fn.dataTableExt.oSort, { "pstring-pre": function ( a ) { diff --git a/sorting/scientific.js b/sorting/scientific.js index e7d308f..a94d246 100644 --- a/sorting/scientific.js +++ b/sorting/scientific.js @@ -1,9 +1,17 @@ /** * This plug-in will treat numbers which are in scientific notation (for - * example 1E-10, 1.2E6 etc) and sort them numerically. + * example `1E-10`, `1.2E6` etc) and sort them numerically. + * * @name Scientific notation sorting - * @anchor scientific - * @author Nick Schurch + * @summary Sort data which is written in exponential notation. + * @author [Nick Schurch](http://datatables.net/forums/profile/21757/nickschurch) + * + * @example + * $('#example').dataTable( { + * columnDefs: [ + * { type: 'scientific', targets: 0 } + * ] + * } ); */ jQuery.extend( jQuery.fn.dataTableExt.oSort, { diff --git a/sorting/signed-num.js b/sorting/signed-num.js index e993dd9..441d302 100644 --- a/sorting/signed-num.js +++ b/sorting/signed-num.js @@ -2,9 +2,17 @@ * Although DataTables' internal numeric sorting works no problem on negative * numbers, it does not accept positively signed numbers. This plug-in will * sort just such data numerically. + * * @name Fully signed numbers sorting - * @anchor Signed_Numbers - * @author Allan Jardine + * @summary Sort data numerically with a leading `+` symbol (as well as `-`). + * @author [Allan Jardine](http://sprymedia.co.uk) + * + * @example + * $('#example').dataTable( { + * columnDefs: [ + * { type: 'signed-num', targets: 0 } + * ] + * } ); */ jQuery.extend( jQuery.fn.dataTableExt.oSort, { diff --git a/sorting/title-numeric.js b/sorting/title-numeric.js index 12fdcb4..eeacfe9 100644 --- a/sorting/title-numeric.js +++ b/sorting/title-numeric.js @@ -1,14 +1,27 @@ /** * An alternative to the formatted number sorting function above (particularly - * useful when considering localisation which uses dots/periods for 10^3 + * useful when considering localisation which uses dots / periods for 10^3 * separation rather than decimal places). Another method of overcoming it * difficulties of sorting formatted numbers is to have the data to be sorted * upon separate from the visual data. This sorting function pair will use the * 'title' attribute of en empty span element (or anything else) to sort - * numerically (for example 1'000'000). + * numerically (for example `1'000'000`). + * + * Note that the HTML5 `data-sort` attribute can be [used to supply sorting data + * to DataTables](//datatables.net/manual/orthogonal-data) and is preferable to + * using this method, which is therefore marked as depreciated. + * * @name Hidden title numeric sorting - * @anchor hidden_title - * @author Allan Jardine + * @summary Sort data numerically based on an attribute on an empty element. + * @depreciated + * @author [Allan Jardine](http://sprymedia.co.uk) + * + * @example + * $('#example').dataTable( { + * columnDefs: [ + * { type: 'title-numeric', targets: 0 } + * ] + * } ); */ jQuery.extend( jQuery.fn.dataTableExt.oSort, { diff --git a/sorting/title-string.js b/sorting/title-string.js index f4b737b..068420d 100644 --- a/sorting/title-string.js +++ b/sorting/title-string.js @@ -1,11 +1,23 @@ /** - * Just like the "hidden title numeric sorting" plug-in, this sorting plug-in + * Just like the _hidden title numeric sorting_ plug-in, this sorting plug-in * will take the information to be sorted on from the title attribute of a span * element. The only difference is that it is string based sorting rather than * numeric. + * + * Note that the HTML5 `data-sort` attribute can be [used to supply sorting data + * to DataTables](//datatables.net/manual/orthogonal-data) and is preferable to + * using this method, which is therefore marked as depreciated. + * * @name Hidden title string sorting - * @anchor hidden_title_string - * @author Allan Jardine + * @summary Sort data as a string based on an attribute on an empty element. + * @author [Allan Jardine](http://sprymedia.co.uk) + * + * @example + * $('#example').dataTable( { + * columnDefs: [ + * { type: 'title-string', targets: 0 } + * ] + * } ); */ jQuery.extend( jQuery.fn.dataTableExt.oSort, { diff --git a/type-detection/currency.js b/type-detection/currency.js index bed22e4..56f0e78 100644 --- a/type-detection/currency.js +++ b/type-detection/currency.js @@ -1,11 +1,17 @@ /** * This plug-in will add automatic detection for currency columns to - * DataTables. Note that only $ and £ symbols are detected with this code, + * 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. + * + * DataTables 1.10+ has currency sorting abilities built-in and will be + * automatically detected. As such this plug-in is marked as depreciated, but + * might be useful when working with old versions of DataTables. + * * @name Currency - * @anchor currency - * @author Allan Jardine, Nuno Gomes + * @summary Detect data of numeric type with a leading currency symbol. + * @depreciated + * @author [Allan Jardine](http://sprymedia.co.uk), Nuno Gomes */ (function(){ diff --git a/type-detection/date-uk.js b/type-detection/date-uk.js index 844c98c..d4a8621 100644 --- a/type-detection/date-uk.js +++ b/type-detection/date-uk.js @@ -1,8 +1,9 @@ /** - * Automatically detect British (dd/mm/yyyy) date types. Goes with the UK + * Automatically detect British (`dd/mm/yyyy`) date types. Goes with the UK * date sorting plug-in. - * @name UK date type detection - * @anchor uk_date + * + * @name Date (`dd/mm/yyyy`) + * @summary Detect data which is in the date format `dd/mm/yyyy` * @author Andy McMaster */ diff --git a/type-detection/file-size.js b/type-detection/file-size.js index de4bfa8..8cfc0d6 100644 --- a/type-detection/file-size.js +++ b/type-detection/file-size.js @@ -2,9 +2,10 @@ * 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 - * @anchor file_size - * @author anjibman + * @summary Detect abbreviated file size data (8MB, 4KB etc) + * @author _anjibman_ */ jQuery.fn.dataTableExt.aTypes.unshift( @@ -12,9 +13,9 @@ jQuery.fn.dataTableExt.aTypes.unshift( { var sValidChars = "0123456789"; var Char; - + /* Check the numeric part */ - for ( i=0 ; i<(sData.length - 3) ; i++ ) + for ( var i=0 ; i<(sData.length - 3) ; i++ ) { Char = sData.charAt(i); if (sValidChars.indexOf(Char) == -1) @@ -22,7 +23,7 @@ jQuery.fn.dataTableExt.aTypes.unshift( 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" diff --git a/type-detection/formatted-num.js b/type-detection/formatted-num.js index 4148127..b547d08 100644 --- a/type-detection/formatted-num.js +++ b/type-detection/formatted-num.js @@ -3,14 +3,19 @@ * 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. + * be. + * + * DataTables 1.10+ has formatted number type detection and sorting abilities + * built-in. As such this plug-in is marked as depreciated, but might be useful + * when working with old versions of DataTables. + * * @name Formatted numbers - * @anchor formatted_numbers - * @author Allan Jardine + * @summary formatted_numbers + * @depreciated + * @author [Allan Jardine](http://sprymedia.co.uk) */ -jQuery.fn.dataTableExt.aTypes.unshift( +jQuery.fn.dataTableExt.aTypes.unshift( function ( sData ) { var deformatted = sData.replace(/[^\d\-\.\/a-zA-Z]/g,''); diff --git a/type-detection/ip-address.js b/type-detection/ip-address.js index 71b4666..f2c23ab 100644 --- a/type-detection/ip-address.js +++ b/type-detection/ip-address.js @@ -1,8 +1,9 @@ /** * Automatically detect IP addresses in dot notation. Goes perfectly with the * IP address sorting function. + * * @name IP address detection - * @anchor ip_address + * @summary Detect data which is in IP address notation * @author Brad Wasson */ diff --git a/type-detection/num-html.js b/type-detection/num-html.js index e732496..65ad6cd 100644 --- a/type-detection/num-html.js +++ b/type-detection/num-html.js @@ -3,9 +3,15 @@ * 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. + * + * DataTables 1.10+ has numeric HTML data type and sorting abilities built-in. + * As such this plug-in is marked as depreciated, but might be useful when + * working with old versions of DataTables. + * * @name Numbers with HTML - * @anchor numbers_html - * @author Allan Jardine + * @summary Detect data which is a mix of HTML and numeric data. + * @depreciated + * @author [Allan Jardine](http://sprymedia.co.uk) */ jQuery.fn.dataTableExt.aTypes.unshift( function ( sData ) @@ -13,28 +19,28 @@ jQuery.fn.dataTableExt.aTypes.unshift( function ( sData ) sData = typeof sData.replace == 'function' ? sData.replace( /<[\s\S]*?>/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) + Char = sData.charAt(0); + if (sValidFirstChars.indexOf(Char) == -1) { return null; } - + /* Check all the other characters are valid */ - for ( var i=1 ; iAllan Jardine + * @summary Detect numeric data which uses a comma as the decimal place. + * @depreciated + * @author [Allan Jardine](http://sprymedia.co.uk) */ jQuery.fn.dataTableExt.aTypes.unshift( @@ -22,9 +24,9 @@ jQuery.fn.dataTableExt.aTypes.unshift( if ( sData.charAt(0) === '-' ) { iStart = 1; } - + /* Check the numeric part */ - for ( i=iStart ; i