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(); }; };