Created
December 8, 2014 20:17
-
-
Save zyzo/58887e4fa06bbad86589 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** Derivative work from date-de plug-in : | |
| * https://github.com/DataTables/Plugins/blob/master/sorting/date-de.js | |
| * | |
| * date and time : dd[DATE_SP]mm[DATE_SP]yy HH[TIME_SP]mm[TIME_SP]ss | |
| * date : dd[DATE_SP]mm[DATE_SP]yy | |
| * | |
| * @author zyzo | |
| * @example | |
| * "columnDefs": [ | |
| {type : 'datetime', targets : 3}, | |
| {type : 'date', targets : 1} | |
| ], | |
| * | |
| **/ | |
| // Date separator | |
| var DATE_SP = '-'; | |
| // Time separator | |
| var TIME_SP = ':' | |
| jQuery.extend( jQuery.fn.dataTableExt.oSort, { | |
| "datetime-asc": function ( a, b ) { | |
| var x, y; | |
| if ($.trim(a) !== '') { | |
| var deDatea = $.trim(a).split(' '); | |
| var deTimea = deDatea[1].split(TIME_SP); | |
| var deDatea2 = deDatea[0].split(DATE_SP); | |
| x = (deDatea2[2] + deDatea2[1] + deDatea2[0] + deTimea[0] + deTimea[1] + deTimea[2]) * 1; | |
| } else { | |
| x = Infinity; // = l'an 1000 ... | |
| } | |
| if ($.trim(b) !== '') { | |
| var deDateb = $.trim(b).split(' '); | |
| var deTimeb = deDateb[1].split(TIME_SP); | |
| deDateb = deDateb[0].split(DATE_SP); | |
| y = (deDateb[2] + deDateb[1] + deDateb[0] + deTimeb[0] + deTimeb[1] + deTimea[2]) * 1; | |
| } else { | |
| y = Infinity; | |
| } | |
| var z = ((x < y) ? -1 : ((x > y) ? 1 : 0)); | |
| return z; | |
| }, | |
| "datetime-desc": function ( a, b ) { | |
| var x, y; | |
| if ($.trim(a) !== '') { | |
| var deDatea = $.trim(a).split(' '); | |
| var deTimea = deDatea[1].split(TIME_SP); | |
| var deDatea2 = deDatea[0].split(DATE_SP); | |
| x = (deDatea2[2] + deDatea2[1] + deDatea2[0] + deTimea[0] + deTimea[1] + deTimea[2]) * 1; | |
| } else { | |
| x = Infinity; | |
| } | |
| if ($.trim(b) !== '') { | |
| var deDateb = $.trim(b).split(' '); | |
| var deTimeb = deDateb[1].split(TIME_SP); | |
| deDateb = deDateb[0].split(DATE_SP); | |
| y = (deDateb[2] + deDateb[1] + deDateb[0] + deTimeb[0] + deTimeb[1] + deTimea[2]) * 1; | |
| } else { | |
| y = Infinity; | |
| } | |
| var z = ((x < y) ? 1 : ((x > y) ? -1 : 0)); | |
| return z; | |
| }, | |
| "date-asc": function ( a, b ) { | |
| var x, y; | |
| if ($.trim(a) !== '') { | |
| var deDatea = $.trim(a).split(DATE_SP); | |
| x = (deDatea[2] + deDatea[1] + deDatea[0]) * 1; | |
| } else { | |
| x = Infinity; // = l'an 1000 ... | |
| } | |
| if ($.trim(b) !== '') { | |
| var deDateb = $.trim(b).split(DATE_SP); | |
| y = (deDateb[2] + deDateb[1] + deDateb[0]) * 1; | |
| } else { | |
| y = Infinity; | |
| } | |
| var z = ((x < y) ? -1 : ((x > y) ? 1 : 0)); | |
| return z; | |
| }, | |
| "date-desc": function ( a, b ) { | |
| var x, y; | |
| if ($.trim(a) !== '') { | |
| var deDatea = $.trim(a).split(DATE_SP); | |
| x = (deDatea[2] + deDatea[1] + deDatea[0]) * 1; | |
| } else { | |
| x = Infinity; | |
| } | |
| if ($.trim(b) !== '') { | |
| var deDateb = $.trim(b).split(DATE_SP); | |
| y = (deDateb[2] + deDateb[1] + deDateb[0]) * 1; | |
| } else { | |
| y = Infinity; | |
| } | |
| var z = ((x < y) ? 1 : ((x > y) ? -1 : 0)); | |
| return z; | |
| } | |
| } ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment