简体   繁体   English

使用Moment.js和订购插件在数据表中按日期(dd.mm.YYYY)排序的问题

[英]Problems with sorting by date (dd.mm.YYYY) in Datatable using Moment.js and Ordering Plugin

I'm trying to make a Datatable sortable using the method described in this blogpost . 我正在尝试使用此Blogpost中描述的方法使Datatable可排序。 As described in the blogpost, I included the two files moment.min.js and datetime-moment.js into my page. 如博客文章中所述,我在页面中包含了两个文件moment.min.js和datetime-moment.js。

My dates are in the following format: 16.03.2015 我的日期采用以下格式: 16.03.2015

Before initialising the datatable, I am executing moment, like: 在初始化数据表之前,我正在执行一下操作,例如:

$.fn.dataTable.moment('dd.mm.YYYY');

$('.datatable').DataTable({
    "retrieve": true,
    "bLengthChange": false,
    "autoWidth": true,
    "responsive": true,
    "oLanguage": {
    ......
    ......

Unfortunately, the table still gets sorted alphabetically when clicking on the date column. 不幸的是,单击日期列时,该表仍按字母顺序排序。 I already tried to change "DataTable" in "dataTable" and vice versa - but it doesn't make any difference! 我已经尝试在“ dataTable”中更改“ DataTable”,反之亦然-但这没有任何区别! Mabye be I have to specify which column is the column with the date? Mabye是我必须指定带有日期的列吗? But I could not find out how to specify it. 但是我找不到如何指定它。 On the Chrome Developer Console there is no error message or log. 在Chrome开发者控制台上,没有错误消息或日志。 It just sorts the date column alphabetically all the time. 它只是一直对日期列进行字母排序。 I could use a different plugin - but the other one is declared as deprecated. 我可以使用其他插件-但另一个插件已声明为已弃用。 Does anybody know what could be the problem that causes this plugin not to sort the datatable? 有人知道导致该插件无法对数据表进行排序的问题是什么吗? Thank you! 谢谢!

You're not using correct date format dd.mm.YYYY , see Moment.js documentation . 您没有使用正确的日期格式dd.mm.YYYY ,请参阅Moment.js文档 dd is day of the week, and mm is minutes. dd是星期几, mm是分钟。

For dates in the format 16.03.2015 use the initialization code below: 对于格式为16.03.2015日期, 16.03.2015使用以下初始化代码:

$.fn.dataTable.moment('DD.MM.YYYY');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM