Skip to content

Commit eb06604

Browse files
committed
Sorting: Date time with moment.js - update to accept null and empty values, which are treated as -Infinity
1 parent 140bc93 commit eb06604

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

sorting/datetime-moment.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,21 @@ $.fn.dataTable.moment = function ( format, locale ) {
2727

2828
// Add type detection
2929
types.detect.unshift( function ( d ) {
30+
// Null and empty values are acceptable
31+
if ( d === '' || d === null ) {
32+
return 'moment-'+format;
33+
}
34+
3035
return moment( d, format, locale, true ).isValid() ?
3136
'moment-'+format :
3237
null;
3338
} );
3439

3540
// Add sorting method - use an integer for the sorting
3641
types.order[ 'moment-'+format+'-pre' ] = function ( d ) {
37-
return moment( d, format, locale, true ).unix();
42+
return d === '' || d === null ?
43+
-Infinity :
44+
moment( d, format, locale, true ).unix();
3845
};
3946
};
4047

0 commit comments

Comments
 (0)