使用Moment.js和Ordering Plugin在Datatable中按日期排序(dd.mm.YYYY)的问题 [英] Problems with sorting by date (dd.mm.YYYY) in Datatable using Moment.js and Ordering Plugin

查看:783
本文介绍了使用Moment.js和Ordering Plugin在Datatable中按日期排序(dd.mm.YYYY)的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用此博客中描述的方法进行Datatable排序。如博客中所述,我将两个文件tim.min.js和datetime-moment.js包含在我的页面中。



我的日期格式如下: 16.03.2015



在初始化datatable之前,我正在执行时刻,如:

  $。fn.dataTable.moment('dd ) 

$('。datatable')。DataTable({
retrieve:true,
bLengthChange:false,
autoWidth:true,
respond:true,
oLanguage:{
......
......
/ pre>

不幸的是,当单击日期列时,表仍然按字母顺序排列。
我已经尝试更改dataTable中的DataTable但是没有任何区别!
Mabye是我必须指定哪个列是列的日期?但是我找不到如何指定它
在Chrome开发者控制台没有错误消息或日志,它只是按字母顺序排列日期列
我可以使用一个不同的插件 - 但另一个被声明为已弃用。有谁知道什么可能是导致这个问题插件不排序datatable?谢谢!

解决方案

您没有使用正确的日期格式 dd .mm.Y YYY ,请参阅 Moment.js文档 dd 是星期几, mm 是分钟。



对于 16.03.2015 格式的日期,请使用以下初始化代码:

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


I'm trying to make a Datatable sortable using the method described in this blogpost. As described in the blogpost, I included the two files moment.min.js and datetime-moment.js into my page.

My dates are in the following format: 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! Mabye be I have to specify which column is the column with the date? But I could not find out how to specify it. On the Chrome Developer Console there is no error message or log. 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 is day of the week, and mm is minutes.

For dates in the format 16.03.2015 use the initialization code below:

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

这篇关于使用Moment.js和Ordering Plugin在Datatable中按日期排序(dd.mm.YYYY)的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆