Sorting: Date time with moment.js - update to accept null and empty values, which are treated as -Infinity

pull/147/head
Allan Jardine 10 years ago
parent 140bc935c2
commit eb06604fdc

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

Loading…
Cancel
Save