From 8c684c1fc7325d3ddfbf36af07465d3de487d5e5 Mon Sep 17 00:00:00 2001 From: BattleMage Date: Fri, 10 Oct 2014 10:59:27 +0200 Subject: [PATCH] Add sorting for dates without time Add type "de_date" to sort columns with just dates without time. --- sorting/date-de.js | 51 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/sorting/date-de.js b/sorting/date-de.js index 7e8131c..e6604d7 100644 --- a/sorting/date-de.js +++ b/sorting/date-de.js @@ -1,15 +1,18 @@ /** - * This sorting plug-in for DataTables will correctly sort data in date time - * format typically used in Germany - `dd.mm.YYYY HH:mm`. + * This sorting plug-in for DataTables will correctly sort data in date time or date + * format typically used in Germany: + * date and time:`dd.mm.YYYY HH:mm` + * just date:`dd.mm.YYYY`. * - * @name Date / time (dd.mm.YYYY HH:mm) - * @summary Sort date / time in the format `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`. * @author [Ronny Vedrilla](http://www.ambient-innovation.com) * * @example * $('#example').dataTable( { * columnDefs: [ - * { type: 'de_datetime', targets: 0 } + * { type: 'de_datetime', targets: 0 }, + * { type: 'de_date', targets: 1 } * ] * } ); */ @@ -59,6 +62,44 @@ } var z = ((x < y) ? 1 : ((x > y) ? -1 : 0)); return z; + }, + + "de_date-asc": function ( a, b ) { + var x, y; + if (j$.trim(a) !== '') { + var deDatea = j$.trim(a).split('.'); + x = (deDatea[2] + deDatea[1] + deDatea[0]) * 1; + } else { + x = Infinity; // = l'an 1000 ... + } + + if (j$.trim(b) !== '') { + var deDateb = j$.trim(b).split('.'); + y = (deDateb[2] + deDateb[1] + deDateb[0]) * 1; + } else { + y = Infinity; + } + var z = ((x < y) ? -1 : ((x > y) ? 1 : 0)); + return z; + }, + + "de_date-desc": function ( a, b ) { + var x, y; + if (j$.trim(a) !== '') { + var deDatea = j$.trim(a).split('.'); + x = (deDatea[2] + deDatea[1] + deDatea[0]) * 1; + } else { + x = Infinity; + } + + if (j$.trim(b) !== '') { + var deDateb = j$.trim(b).split('.'); + y = (deDateb[2] + deDateb[1] + deDateb[0]) * 1; + } else { + y = Infinity; + } + var z = ((x < y) ? 1 : ((x > y) ? -1 : 0)); + return z; } } );