I'm using jquery DataTable plugin and in one of my tables, I wanted to sort the result based on the date time column. So, I included moment.js version 2.13.0 and my dataTable version is 1.10.10 and my jQuery version is 1.9.1.
As suggested in this latest dataTable date time sorting plugin article https://datatables.net/blog/2014-12-18, I tried the following but in the console I have
TypeError: $.fn.dataTable.moment is not a function
$.fn.dataTable.moment('DD-MMM-Y HH:mm:ss');
in my html page,
$(document).ready(function() {
$.fn.dataTable.moment('DD-MMM-Y HH:mm:ss');
$('#myTable').DataTable();
} );
My Date column data has date in this format, 09-May-2016 19:38:00
. And I have interchanged the order in which the dataTable and moment.js plugin source is included in my html page. But I still get the same error. What could be the issue?
The order of importing the scripts is important. You have to include datatables before the sorting plugin. The following works for me:
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.2/moment.min.js"></script>
<script src="//cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script src="//cdn.datatables.net/plug-ins/1.10.12/sorting/datetime-moment.js"></script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With