New - sorting: "Ultimate" date / time sorting plug-in for DataTables using Moment.JS

pull/139/head
Allan Jardine 10 years ago
parent 07a93c6e1e
commit 25aa4c8780

@ -7,9 +7,14 @@
* * 17-MAY-2013 * * 17-MAY-2013
* * 31-JAN-2014 * * 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) * @name Date (dd-mmm-yyyy)
* @summary Sort dates in the format `dd-mmm-yyyy` * @summary Sort dates in the format `dd-mmm-yyyy`
* @author [Jeromy French](http://www.appliedinter.net/jeromy_works/) * @author [Jeromy French](http://www.appliedinter.net/jeromy_works/)
* @deprecated
* *
* @example * @example
* $('#example').dataTable( { * $('#example').dataTable( {

@ -4,9 +4,14 @@
* date and time:`dd.mm.YYYY HH:mm` * date and time:`dd.mm.YYYY HH:mm`
* just date:`dd.mm.YYYY`. * 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) * @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`. * @summary Sort date / time in the format `dd.mm.YYYY HH:mm` or `dd.mm.YYYY`.
* @author [Ronny Vedrilla](http://www.ambient-innovation.com) * @author [Ronny Vedrilla](http://www.ambient-innovation.com)
* @deprecated
* *
* @example * @example
* $('#example').dataTable( { * $('#example').dataTable( {
@ -20,8 +25,8 @@
jQuery.extend( jQuery.fn.dataTableExt.oSort, { jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"de_datetime-asc": function ( a, b ) { "de_datetime-asc": function ( a, b ) {
var x, y; var x, y;
if ($.trim(a) !== '') { if (jQuery.trim(a) !== '') {
var deDatea = $.trim(a).split(' '); var deDatea = jQuery.trim(a).split(' ');
var deTimea = deDatea[1].split(':'); var deTimea = deDatea[1].split(':');
var deDatea2 = deDatea[0].split('.'); var deDatea2 = deDatea[0].split('.');
x = (deDatea2[2] + deDatea2[1] + deDatea2[0] + deTimea[0] + deTimea[1]) * 1; x = (deDatea2[2] + deDatea2[1] + deDatea2[0] + deTimea[0] + deTimea[1]) * 1;
@ -29,8 +34,8 @@
x = Infinity; // = l'an 1000 ... x = Infinity; // = l'an 1000 ...
} }
if ($.trim(b) !== '') { if (jQuery.trim(b) !== '') {
var deDateb = $.trim(b).split(' '); var deDateb = jQuery.trim(b).split(' ');
var deTimeb = deDateb[1].split(':'); var deTimeb = deDateb[1].split(':');
deDateb = deDateb[0].split('.'); deDateb = deDateb[0].split('.');
y = (deDateb[2] + deDateb[1] + deDateb[0] + deTimeb[0] + deTimeb[1]) * 1; y = (deDateb[2] + deDateb[1] + deDateb[0] + deTimeb[0] + deTimeb[1]) * 1;
@ -43,8 +48,8 @@
"de_datetime-desc": function ( a, b ) { "de_datetime-desc": function ( a, b ) {
var x, y; var x, y;
if ($.trim(a) !== '') { if (jQuery.trim(a) !== '') {
var deDatea = $.trim(a).split(' '); var deDatea = jQuery.trim(a).split(' ');
var deTimea = deDatea[1].split(':'); var deTimea = deDatea[1].split(':');
var deDatea2 = deDatea[0].split('.'); var deDatea2 = deDatea[0].split('.');
x = (deDatea2[2] + deDatea2[1] + deDatea2[0] + deTimea[0] + deTimea[1]) * 1; x = (deDatea2[2] + deDatea2[1] + deDatea2[0] + deTimea[0] + deTimea[1]) * 1;
@ -52,8 +57,8 @@
x = Infinity; x = Infinity;
} }
if ($.trim(b) !== '') { if (jQuery.trim(b) !== '') {
var deDateb = $.trim(b).split(' '); var deDateb = jQuery.trim(b).split(' ');
var deTimeb = deDateb[1].split(':'); var deTimeb = deDateb[1].split(':');
deDateb = deDateb[0].split('.'); deDateb = deDateb[0].split('.');
y = (deDateb[2] + deDateb[1] + deDateb[0] + deTimeb[0] + deTimeb[1]) * 1; y = (deDateb[2] + deDateb[1] + deDateb[0] + deTimeb[0] + deTimeb[1]) * 1;
@ -66,15 +71,15 @@
"de_date-asc": function ( a, b ) { "de_date-asc": function ( a, b ) {
var x, y; var x, y;
if ($.trim(a) !== '') { if (jQuery.trim(a) !== '') {
var deDatea = $.trim(a).split('.'); var deDatea = jQuery.trim(a).split('.');
x = (deDatea[2] + deDatea[1] + deDatea[0]) * 1; x = (deDatea[2] + deDatea[1] + deDatea[0]) * 1;
} else { } else {
x = Infinity; // = l'an 1000 ... x = Infinity; // = l'an 1000 ...
} }
if ($.trim(b) !== '') { if (jQuery.trim(b) !== '') {
var deDateb = $.trim(b).split('.'); var deDateb = jQuery.trim(b).split('.');
y = (deDateb[2] + deDateb[1] + deDateb[0]) * 1; y = (deDateb[2] + deDateb[1] + deDateb[0]) * 1;
} else { } else {
y = Infinity; y = Infinity;
@ -85,15 +90,15 @@
"de_date-desc": function ( a, b ) { "de_date-desc": function ( a, b ) {
var x, y; var x, y;
if ($.trim(a) !== '') { if (jQuery.trim(a) !== '') {
var deDatea = $.trim(a).split('.'); var deDatea = jQuery.trim(a).split('.');
x = (deDatea[2] + deDatea[1] + deDatea[0]) * 1; x = (deDatea[2] + deDatea[1] + deDatea[0]) * 1;
} else { } else {
x = Infinity; x = Infinity;
} }
if ($.trim(b) !== '') { if (jQuery.trim(b) !== '') {
var deDateb = $.trim(b).split('.'); var deDateb = jQuery.trim(b).split('.');
y = (deDateb[2] + deDateb[1] + deDateb[0]) * 1; y = (deDateb[2] + deDateb[1] + deDateb[0]) * 1;
} else { } else {
y = Infinity; y = Infinity;

@ -3,9 +3,14 @@
* additional flexibility with support for spaces between the values and * additional flexibility with support for spaces between the values and
* either . or / notation for the separators. * 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]) * @name Date (dd . mm[ . YYYY])
* @summary Sort dates in the format `dd/mm/YY[YY]` (with optional spaces) * @summary Sort dates in the format `dd/mm/YY[YY]` (with optional spaces)
* @author [Robert Sedovšek](http://galjot.si/) * @author [Robert Sedovšek](http://galjot.si/)
* @deprecated
* *
* @example * @example
* $('#example').dataTable( { * $('#example').dataTable( {

@ -4,9 +4,14 @@
* also be quickly adapted for other formatting as required. Furthermore, this * also be quickly adapted for other formatting as required. Furthermore, this
* date sorting plug-in allows for empty values in the column. * 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) * @name Date (dd/mm/YYY hh:ii:ss)
* @summary Sort date / time in the format `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/) * @author [Ronan Guilloux](http://coolforest.net/)
* @deprecated
* *
* @example * @example
* $('#example').dataTable( { * $('#example').dataTable( {

@ -6,9 +6,14 @@
* *
* An automatic type detection plug-in is available for this sorting plug-in. * 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) * @name Date (dd/mm/YY)
* @summary Sort dates in the format `dd/mm/YY` * @summary Sort dates in the format `dd/mm/YY`
* @author Andy McMaster * @author Andy McMaster
* @deprecated
* *
* @example * @example
* $('#example').dataTable( { * $('#example').dataTable( {

@ -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));

@ -8,9 +8,14 @@
* * 01/01/2013 01:04 PM * * 01/01/2013 01:04 PM
* * 1/1/2013 1: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 * @name Date / time - US
* @summary Sort date / time in the format `m/d/yy h:m am|pm` * @summary Sort date / time in the format `m/d/yy h:m am|pm`
* @author [Kevin Gravier](http://mrkmg.com/) * @author [Kevin Gravier](http://mrkmg.com/)
* @deprecated
* *
* @example * @example
* $('#example').dataTable( { * $('#example').dataTable( {

@ -2,9 +2,14 @@
* This sorting plug-in will sort, in calendar order, data which * This sorting plug-in will sort, in calendar order, data which
* is in the format "MM YY". * 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) * @name Date (MM YY)
* @anchor Sort dates in the format `MM YY` * @anchor Sort dates in the format `MM YY`
* @author Michael Motek * @author Michael Motek
* @deprecated
* *
* @example * @example
* $('#example').dataTable( { * $('#example').dataTable( {

@ -3,9 +3,14 @@
* is in the format "MMM yyyy" or "MMMM yyyy". Inspired by forum discussion: * 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 * 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) * @name Date (MMM yyyy) or (MMMM yyyy)
* @anchor Sort dates in the format `MMM yyyy` or `MMMM yyyy` * @anchor Sort dates in the format `MMM yyyy` or `MMMM yyyy`
* @author Phil Hurwitz * @author Phil Hurwitz
* @deprecated
* *
* @example * @example
* $('#example').DataTable( { * $('#example').DataTable( {

@ -3,11 +3,16 @@
* information in the most common formats used. It will automatically detect * information in the most common formats used. It will automatically detect
* those date types. * 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) * @name Time (dd/mm/YY)
* @summary Sort Times in the formats: `hh:mm, hh:mm:ss, hh:mm tt, hh:mm:ss tt` * @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' * 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 * am and pm are not case sensitive. white space is not compulsory
* @author David Stoneham * @author David Stoneham
* @deprecated
* *
* @example * @example
* $('#example').dataTable( { * $('#example').dataTable( {

Loading…
Cancel
Save