From eb06604fdc9d5ae612684add135983b21c6f3573 Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Mon, 19 Jan 2015 11:05:02 +0000 Subject: [PATCH] Sorting: Date time with moment.js - update to accept null and empty values, which are treated as -Infinity --- sorting/datetime-moment.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sorting/datetime-moment.js b/sorting/datetime-moment.js index e5fe738..0bb713b 100644 --- a/sorting/datetime-moment.js +++ b/sorting/datetime-moment.js @@ -27,6 +27,11 @@ $.fn.dataTable.moment = function ( format, locale ) { // Add type detection types.detect.unshift( function ( d ) { + // Null and empty values are acceptable + if ( d === '' || d === null ) { + return 'moment-'+format; + } + return moment( d, format, locale, true ).isValid() ? 'moment-'+format : null; @@ -34,7 +39,9 @@ $.fn.dataTable.moment = function ( format, locale ) { // Add sorting method - use an integer for the sorting types.order[ 'moment-'+format+'-pre' ] = function ( d ) { - return moment( d, format, locale, true ).unix(); + return d === '' || d === null ? + -Infinity : + moment( d, format, locale, true ).unix(); }; };