日期排序问题
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;
}
更多相关文章
- 尽管referesh,jQuery格式化不适用于ajax数据
- xml格式原样输出到html或是jsp页面
- flah网站发布问题,我是在flash里面直接发布成html格式,如何提示安
- Ajax技术--服务器返回数据格式(HTML,XML,JSON)
- Nodejs中利用phantom把html转为pdf或图片格式
- 如何用Cdont+ASP发送带附件的html格式邮件
- 2.html5的基本格式
- java中json数据格式的应用
- HTML代码格式化工具