Cannot get DataTables date sort working with moment.js
Cannot get DataTables date sort working with moment.js
Hello everyone, having trouble with this issue and have exhausted all of the forums looking for answers (mostly https://datatables.net/blog/2014-12-18 <- this blog post)
I want to use the moment.js plugin (described in above blog post) to sort a simple table
The following is in my code,
$(document).ready(function() {
//These are the formats I have tried, separately, and many combined
$.fn.dataTable.moment( 'MMMM DD, YYYY, hh:mm a' );
$.fn.dataTable.moment( 'MMMM DD, YYYY, h:mm a' );
$.fn.dataTable.moment( 'MMMM DD, YYYY, hh a' );
$.fn.dataTable.moment( 'MMMM DD, YYYY, h a' );
$.fn.dataTable.moment( 'MMMM D, YYYY, hh:mm a' );
$.fn.dataTable.moment( 'MMMM D, YYYY, h a' );
$.fn.dataTable.moment( 'MMMM D, YYYY, hh a' );
$('#table_selector').DataTable({
"order": [[ 1, "desc" ]]
});
});
The actual table is rendered like this (It ends up being rendered as a non-ajaxy, static table):
{% for row in table_data %}
<tr><td> {{row.name}} </td> <td data-order="{{row.date}}"><a href="...">{{row.date}}</a></td></tr>
{% endfor %}
Rendered, it looks like this
| John | June 9, 2017, 7:59 p.m. |
| Mary | June 7, 2017, 11 a.m. |
| Allan | June 12, 2017, 3 a.m. |
DT is attempting to sort the column I selected (notable by the down-caret in the header) but I clearly I initialized something incorrectly. There are no console errors, so I'm a bit lost. I know moment.js is loaded, as well as the datetime-moment.js referenced in the above blog post because I can reference them in the console without errors.I'm sure I'm doing something wrong, but can't figure out what!
Any tips?
Answers
Hi,
I have a column of dates which has this format MM/DD/YYYY. Sorting is not properly working for this format(MM/DD/YYYY). Could you help me?