数据表:日期/时间排序插件

时间:2017-05-28 10:07:56

标签: javascript jquery html datatable datatables

我想订购数据表的1个日期列。 这是我的一段代码:

<script src="https://cdn.datatables.net/plug-ins/1.10.15/sorting/datetime-moment.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js"></script>

<script th:inline="javascript">
$(document).ready(function() {

    $.fn.dataTable.moment( 'EEEE, MMMM d,yyyy h:mm,a' );

    $('#table').dataTable( {  
        "bLengthChange": false,
        "pageLength": 25,
    }); 
} );
</script>

但是我收到了这个错误:

jQuery.Deferred exception: $.fn.dataTable.moment is not a function TypeError: $.fn.dataTable.moment is not a function
    at HTMLDocument.<anonymous> 

1 个答案:

答案 0 :(得分:0)

确保在插件 之前引用moment.js

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js"></script>
<script src="https://cdn.datatables.net/plug-ins/1.10.15/sorting/datetime-moment.js"></script>

<script th:inline="javascript">
$(document).ready(function() {

    $.fn.dataTable.moment( 'EEEE, MMMM d,yyyy h:mm,a' );

    $('#table').dataTable( {  
        "bLengthChange": false,
        "pageLength": 25,
    }); 
} );
</script>