diff --git a/sorting/date-dd-MMM-yyyy.js b/sorting/date-dd-MMM-yyyy.js index c11e02f..d42a804 100644 --- a/sorting/date-dd-MMM-yyyy.js +++ b/sorting/date-dd-MMM-yyyy.js @@ -7,9 +7,14 @@ * * 17-MAY-2013 * * 31-JAN-2014 * + * Please note that this plug-in is **deprecated*. The + * [datetime](//datatables.net/blog/2014-12-18) plug-in provides enhanced + * functionality and flexibility. + * * @name Date (dd-mmm-yyyy) * @summary Sort dates in the format `dd-mmm-yyyy` * @author [Jeromy French](http://www.appliedinter.net/jeromy_works/) + * @deprecated * * @example * $('#example').dataTable( { diff --git a/sorting/date-de.js b/sorting/date-de.js index c97018d..0a5a096 100644 --- a/sorting/date-de.js +++ b/sorting/date-de.js @@ -4,9 +4,14 @@ * date and time:`dd.mm.YYYY HH:mm` * just date:`dd.mm.YYYY`. * + * Please note that this plug-in is **deprecated*. The + * [datetime](//datatables.net/blog/2014-12-18) plug-in provides enhanced + * functionality and flexibility. + * * @name Date (dd.mm.YYYY) or date and time (dd.mm.YYYY HH:mm) * @summary Sort date / time in the format `dd.mm.YYYY HH:mm` or `dd.mm.YYYY`. * @author [Ronny Vedrilla](http://www.ambient-innovation.com) + * @deprecated * * @example * $('#example').dataTable( { @@ -20,8 +25,8 @@ jQuery.extend( jQuery.fn.dataTableExt.oSort, { "de_datetime-asc": function ( a, b ) { var x, y; - if ($.trim(a) !== '') { - var deDatea = $.trim(a).split(' '); + if (jQuery.trim(a) !== '') { + var deDatea = jQuery.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; @@ -29,8 +34,8 @@ x = Infinity; // = l'an 1000 ... } - if ($.trim(b) !== '') { - var deDateb = $.trim(b).split(' '); + if (jQuery.trim(b) !== '') { + var deDateb = jQuery.trim(b).split(' '); var deTimeb = deDateb[1].split(':'); deDateb = deDateb[0].split('.'); y = (deDateb[2] + deDateb[1] + deDateb[0] + deTimeb[0] + deTimeb[1]) * 1; @@ -43,8 +48,8 @@ "de_datetime-desc": function ( a, b ) { var x, y; - if ($.trim(a) !== '') { - var deDatea = $.trim(a).split(' '); + if (jQuery.trim(a) !== '') { + var deDatea = jQuery.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; @@ -52,8 +57,8 @@ x = Infinity; } - if ($.trim(b) !== '') { - var deDateb = $.trim(b).split(' '); + if (jQuery.trim(b) !== '') { + var deDateb = jQuery.trim(b).split(' '); var deTimeb = deDateb[1].split(':'); deDateb = deDateb[0].split('.'); y = (deDateb[2] + deDateb[1] + deDateb[0] + deTimeb[0] + deTimeb[1]) * 1; @@ -66,15 +71,15 @@ "de_date-asc": function ( a, b ) { var x, y; - if ($.trim(a) !== '') { - var deDatea = $.trim(a).split('.'); + if (jQuery.trim(a) !== '') { + var deDatea = jQuery.trim(a).split('.'); x = (deDatea[2] + deDatea[1] + deDatea[0]) * 1; } else { x = Infinity; // = l'an 1000 ... } - if ($.trim(b) !== '') { - var deDateb = $.trim(b).split('.'); + if (jQuery.trim(b) !== '') { + var deDateb = jQuery.trim(b).split('.'); y = (deDateb[2] + deDateb[1] + deDateb[0]) * 1; } else { y = Infinity; @@ -85,15 +90,15 @@ "de_date-desc": function ( a, b ) { var x, y; - if ($.trim(a) !== '') { - var deDatea = $.trim(a).split('.'); + if (jQuery.trim(a) !== '') { + var deDatea = jQuery.trim(a).split('.'); x = (deDatea[2] + deDatea[1] + deDatea[0]) * 1; } else { x = Infinity; } - if ($.trim(b) !== '') { - var deDateb = $.trim(b).split('.'); + if (jQuery.trim(b) !== '') { + var deDateb = jQuery.trim(b).split('.'); y = (deDateb[2] + deDateb[1] + deDateb[0]) * 1; } else { y = Infinity; diff --git a/sorting/date-eu.js b/sorting/date-eu.js index fabc249..fdda790 100644 --- a/sorting/date-eu.js +++ b/sorting/date-eu.js @@ -3,9 +3,14 @@ * additional flexibility with support for spaces between the values and * either . or / notation for the separators. * + * Please note that this plug-in is **deprecated*. The + * [datetime](//datatables.net/blog/2014-12-18) plug-in provides enhanced + * functionality and flexibility. + * * @name Date (dd . mm[ . YYYY]) * @summary Sort dates in the format `dd/mm/YY[YY]` (with optional spaces) * @author [Robert Sedovšek](http://galjot.si/) + * @deprecated * * @example * $('#example').dataTable( { diff --git a/sorting/date-euro.js b/sorting/date-euro.js index 6ac5ae6..a2e0758 100644 --- a/sorting/date-euro.js +++ b/sorting/date-euro.js @@ -4,9 +4,14 @@ * also be quickly adapted for other formatting as required. Furthermore, this * date sorting plug-in allows for empty values in the column. * + * Please note that this plug-in is **deprecated*. The + * [datetime](//datatables.net/blog/2014-12-18) plug-in provides enhanced + * functionality and flexibility. + * * @name Date (dd/mm/YYY hh:ii:ss) * @summary Sort date / time in the format `dd/mm/YYY hh:ii:ss` * @author [Ronan Guilloux](http://coolforest.net/) + * @deprecated * * @example * $('#example').dataTable( { diff --git a/sorting/date-uk.js b/sorting/date-uk.js index 903f988..527ea6c 100644 --- a/sorting/date-uk.js +++ b/sorting/date-uk.js @@ -6,9 +6,14 @@ * * An automatic type detection plug-in is available for this sorting plug-in. * + * Please note that this plug-in is **deprecated*. The + * [datetime](//datatables.net/blog/2014-12-18) plug-in provides enhanced + * functionality and flexibility. + * * @name Date (dd/mm/YY) * @summary Sort dates in the format `dd/mm/YY` * @author Andy McMaster + * @deprecated * * @example * $('#example').dataTable( { diff --git a/sorting/datetime-moment.js b/sorting/datetime-moment.js new file mode 100644 index 0000000..e5fe738 --- /dev/null +++ b/sorting/datetime-moment.js @@ -0,0 +1,41 @@ +/** + * This plug-in for DataTables represents the ultimate option in extensibility + * for sorting date / time strings correctly. It uses + * [Moment.js](http://momentjs.com) to create automatic type detection and + * sorting plug-ins for DataTables based on a given format. This way, DataTables + * will automatically detect your temporal information and sort it correctly. + * + * For usage instructions, please see the DataTables blog + * post that [introduces it](//datatables.net/blog/2014-12-18). + * + * @name Ultimate Date / Time sorting + * @summary Sort date and time in any format using Moment.js + * @author [Allan Jardine](//datatables.net) + * @depends DataTables 1.10+, Moment.js 1.7+ + * + * @example + * $.fn.dataTable.moment( 'HH:mm MMM D, YY' ); + * $.fn.dataTable.moment( 'dddd, MMMM Do, YYYY' ); + * + * $('#example').DataTable(); + */ + +(function($) { + +$.fn.dataTable.moment = function ( format, locale ) { + var types = $.fn.dataTable.ext.type; + + // Add type detection + types.detect.unshift( function ( d ) { + return moment( d, format, locale, true ).isValid() ? + 'moment-'+format : + null; + } ); + + // Add sorting method - use an integer for the sorting + types.order[ 'moment-'+format+'-pre' ] = function ( d ) { + return moment( d, format, locale, true ).unix(); + }; +}; + +}(jQuery)); diff --git a/sorting/datetime-us.js b/sorting/datetime-us.js index 91ab51b..3546ef7 100644 --- a/sorting/datetime-us.js +++ b/sorting/datetime-us.js @@ -8,9 +8,14 @@ * * 01/01/2013 01:04 PM * * 1/1/2013 1:04 Pm * + * Please note that this plug-in is **deprecated*. The + * [datetime](//datatables.net/blog/2014-12-18) plug-in provides enhanced + * functionality and flexibility. + * * @name Date / time - US * @summary Sort date / time in the format `m/d/yy h:m am|pm` * @author [Kevin Gravier](http://mrkmg.com/) + * @deprecated * * @example * $('#example').dataTable( { diff --git a/sorting/monthYear.js b/sorting/monthYear.js index 8668e08..54d9d82 100644 --- a/sorting/monthYear.js +++ b/sorting/monthYear.js @@ -2,9 +2,14 @@ * This sorting plug-in will sort, in calendar order, data which * is in the format "MM YY". * + * Please note that this plug-in is **deprecated*. The + * [datetime](//datatables.net/blog/2014-12-18) plug-in provides enhanced + * functionality and flexibility. + * * @name Date (MM YY) * @anchor Sort dates in the format `MM YY` * @author Michael Motek + * @deprecated * * @example * $('#example').dataTable( { diff --git a/sorting/stringMonthYear.js b/sorting/stringMonthYear.js index bbacff2..ffcd330 100644 --- a/sorting/stringMonthYear.js +++ b/sorting/stringMonthYear.js @@ -3,9 +3,14 @@ * is in the format "MMM yyyy" or "MMMM yyyy". Inspired by forum discussion: * http://datatables.net/forums/discussion/1242/sorting-dates-with-only-month-and-year * + * Please note that this plug-in is **deprecated*. The + * [datetime](//datatables.net/blog/2014-12-18) plug-in provides enhanced + * functionality and flexibility. + * * @name Date (MMM yyyy) or (MMMM yyyy) * @anchor Sort dates in the format `MMM yyyy` or `MMMM yyyy` * @author Phil Hurwitz + * @deprecated * * @example * $('#example').DataTable( { diff --git a/sorting/time.js b/sorting/time.js index 3258ea1..b0354b2 100644 --- a/sorting/time.js +++ b/sorting/time.js @@ -3,11 +3,16 @@ * information in the most common formats used. It will automatically detect * those date types. * + * Please note that this plug-in is **deprecated*. The + * [datetime](//datatables.net/blog/2014-12-18) plug-in provides enhanced + * functionality and flexibility. + * * @name Time (dd/mm/YY) * @summary Sort Times in the formats: `hh:mm, hh:mm:ss, hh:mm tt, hh:mm:ss tt` * e.g. '22:50, 22:50:40, 10:50 pm, 10:50:40 pm' * am and pm are not case sensitive. white space is not compulsory * @author David Stoneham + * @deprecated * * @example * $('#example').dataTable( {