diff --git a/sorting/datetime-moment.js b/sorting/datetime-moment.js index 35af232..0ac9abe 100644 --- a/sorting/datetime-moment.js +++ b/sorting/datetime-moment.js @@ -20,6 +20,12 @@ * $('#example').DataTable(); */ +function strip(html) { + var tmp = document.createElement("DIV"); + tmp.innerHTML = html; + return tmp.textContent || tmp.innerText || ""; +} + (function($) { $.fn.dataTable.moment = function ( format, locale ) { @@ -32,7 +38,7 @@ $.fn.dataTable.moment = function ( format, locale ) { return 'moment-'+format; } - return moment( d, format, locale, true ).isValid() ? + return moment( strip(d), format, locale, true ).isValid() ? 'moment-'+format : null; } ); @@ -41,7 +47,7 @@ $.fn.dataTable.moment = function ( format, locale ) { types.order[ 'moment-'+format+'-pre' ] = function ( d ) { return d === '' || d === null ? -Infinity : - parseInt( moment( d, format, locale, true ).format( 'x' ), 10 ); + parseInt( moment( strip(d), format, locale, true ).format( 'x' ), 10 ); }; };