Merge pull request #292 from milestonetg/momentjs-parse-fix

Sorting: Changed datetime-moment to strip out newline characters and surrounding whitespace
pull/295/head
Allan Jardine 8 years ago committed by GitHub
commit 0e201c0016

@ -33,10 +33,16 @@ $.fn.dataTable.moment = function ( format, locale ) {
// Add type detection
types.detect.unshift( function ( d ) {
// Strip HTML tags if possible
if ( d && d.replace ) {
d = d.replace(/<.*?>/g, '');
}
if ( d ) {
// Strip HTML tags and newline characters if possible
if ( d.replace ) {
d = d.replace(/(<.*?>)|(\r?\n|\r)/g, '');
}
// Strip out surrounding whitespace if possible
if ( d.trim ) {
d = d.trim();
}
}
// Null and empty values are acceptable
if ( d === '' || d === null ) {
@ -50,9 +56,17 @@ $.fn.dataTable.moment = function ( format, locale ) {
// Add sorting method - use an integer for the sorting
types.order[ 'moment-'+format+'-pre' ] = function ( d ) {
if ( d && d.replace ) {
d = d.replace(/<.*?>/g, '');
}
if ( d ) {
// Strip HTML tags and newline characters if possible
if ( d.replace ) {
d = d.replace(/(<.*?>)|(\r?\n|\r)/g, '');
}
// Strip out surrounding whitespace if possible
if ( d.trim ) {
d = d.trim();
}
}
return d === '' || d === null ?
-Infinity :
parseInt( moment( d, format, locale, true ).format( 'x' ), 10 );

Loading…
Cancel
Save