Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: $.fn.dataTable.moment is not a function

Tags:

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?

like image 486
Lucky Avatar asked May 09 '16 14:05

Lucky


1 Answers

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>
like image 108
Ossipon Avatar answered Oct 19 '22 06:10

Ossipon