https://communitychessclub.com/examine.php DataTables with moment.js is sorting date as a string, not a date. How can I get a sample date of "08/23/2018" to sort properly? That is, I want to sort "mm/dd/yyyy". I simply can't get this to work.
<script src="//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js"></script>
<script src="//cdn.datatables.net/plug-ins/1.10.19/sorting/datetime-moment.js"></script>
<script src="js/dataTables.keepConditions.min.js"></script>
<script>
$.fn.dataTable.moment = function ( format, locale ) {
var types = $.fn.dataTable.ext.type;
// Add type detection
types.detect.unshift( function ( d ) {
return moment( d, format, locale, true ).isValid() ?
'moment-'+format :
null;
} );
// Add sorting method - use an integer for the sorting
types.order[ 'moment-'+format+'-pre' ] = function ( d ) {
return moment( d, format, locale, true ).unix();
};
};
</script>
<script>
$(document).ready(function() {
$.fn.dataTable.moment( 'MM/DD/YYYY' );
$('#cccr').DataTable( {
"ajax": "assets/games.ajax",
"pageLength": 25,
"order": [[ 8, "desc" ]],
"columns": [
{ "data": "Date", "width": "7rem", },
{ "data": "Event" },
{ "data": "ECO" },
{ "data": "White" },
{ "data": "WhiteElo" },
{ "data": "Black" },
{ "data": "BlackElo" },
{ "data": "Result" },
{ "data": "game", visible : false }
]
} );
} );
</script>
$.fn.dataTable.moment( 'MM/DD/YYYY' );defined in the referred webpage. Can you make sure that's defined?