I am using a Jquery plugin called datatables

我使用的是Jquery插件datatables

Its fantastic, however I cannot get the dates to sort correctly according to the dd/mm/yyyy format.

太棒了,但是我不能按照dd/mm/yyyy格式得到正确的日期排序。

I have looked at their support formats but none of these fixes seem to work.

我查看了它们的支持格式,但这些修复似乎都不起作用。

Can anybody here help me please?

这里有人能帮我吗?

18 个解决方案

#1


74

jQuery Solution

Here is working jQuery solution.

下面是jQuery解决方案。

jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"date-uk-pre": function ( a ) {
    var ukDatea = a.split('/');
    return (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1;
},

"date-uk-asc": function ( a, b ) {
    return ((a < b) ? -1 : ((a > b) ? 1 : 0));
},

"date-uk-desc": function ( a, b ) {
    return ((a < b) ? 1 : ((a > b) ? -1 : 0));
}
} );

Add the above code to script and set the specific column with Date values with { "sType": "date-uk" } and others as null, see below:

将上述代码添加到脚本中,并将具有{“sType”:“Date -uk”}的日期值的特定列设置为null,见下文:

$(document).ready(function() {
    $('#example').dataTable( {
        "aoColumns": [
            null,
            null,
            null,
            null,
            { "sType": "date-uk" },
            null
        ]
    });
    });

CSS Solution

If you want a quick solution you can just append the actual DateTime value in each row in the specific format (YYYYMMDD) and make it hidden using CSS, it will allow you to sort that column without any javascript change.

如果您想要一个快速的解决方案,您只需在每一行中添加具体格式(yyyyyymmdd)的实际DateTime值,并使用CSS将其隐藏起来,它将允许您在没有任何javascript更改的情况下对该列进行排序。

Here is working CSS solution

这是可用的CSS解决方案

HTML

HTML

<td><span class='hide'>YYYYMMDD</span>DD/MM/YYYY</td>

CSS

CSS

.hide {
    display:none; 
}

更多相关文章

  1. 尽管referesh,jQuery格式化不适用于ajax数据
  2. xml格式原样输出到html或是jsp页面
  3. flah网站发布问题,我是在flash里面直接发布成html格式,如何提示安
  4. Ajax技术--服务器返回数据格式(HTML,XML,JSON)
  5. Nodejs中利用phantom把html转为pdf或图片格式
  6. 如何用Cdont+ASP发送带附件的html格式邮件
  7. 2.html5的基本格式
  8. java中json数据格式的应用
  9. HTML代码格式化工具

随机推荐

  1. COVID-19每日数据|04-09
  2. 【决战西二旗】|理解标准模板库STL(一)
  3. 我常用的10个Python实用小Trick
  4. 图解:什么是 JS 原型和原型链?
  5. Pandas进阶修炼120题同步视频现已登陆
  6. 【决战西二旗】|你真的懂快速排序?
  7. 词云图的几种制作方法评测,你pick哪款
  8. 动画:用动画给女朋友讲解 TCP 四次分手过
  9. 浅谈集群版Redis和Gossip协议
  10. 什么!Python还能帮你找老婆?