From 0f8ec6f7de43780e9c09d2f44517cdec5cac9d17 Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Mon, 19 Oct 2015 12:35:08 +0100 Subject: [PATCH] Sorting: Update moment date / time to strip HTML tags before checking for empty - Update suggested by sporring - thanks! --- sorting/datetime-moment.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sorting/datetime-moment.js b/sorting/datetime-moment.js index aae10d9..13b05b1 100644 --- a/sorting/datetime-moment.js +++ b/sorting/datetime-moment.js @@ -27,12 +27,17 @@ $.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, '') ) { + } + // Null and empty values are acceptable if ( d === '' || d === null ) { return 'moment-'+format; } - return moment( d.replace ? d.replace(/<.*?>/g, '') : d, format, locale, true ).isValid() ? + return moment( d, format, locale, true ).isValid() ? 'moment-'+format : null; } );