数据表中的排序日期 [英] Sorting date in datatable
问题描述
我正在尝试对数据表中的日期进行排序,例如DD/MM/YYYY
(日,月,年).
我正在关注 https://datatables.net/plug-ins/sorting/.
I'm trying to sort dates in my datatable like DD/MM/YYYY
(day, month, year) .
I was following https://datatables.net/plug-ins/sorting/ .
,但所有日期排序似乎都已弃用,并指向datetime插件: https://datatables.net/blog/2014-12-18
but all the date sorts seem to be deprecated and point to the datetime plugin: https://datatables.net/blog/2014-12-18
我似乎无法使datetime插件正常工作.我尝试了旧的约会方式.初始化看起来像这样:
I don't seem to be able to get the datetime plugin working to sort. I tried the old way, with date. The initialize looks like this:
var historiektable = $('#dataTableHistoriek').DataTable({
"paging" : false,
"ordering" : true,
"scrollCollapse" : true,
"searching" : false,
"columnDefs" : [{"targets":3, "type":"date"}],
"bInfo": true
});
不进行排序就显示表格结果,如下所示:
Without sorting it shows the table results like this:
当我放入ordering:true
时,2016年的2个日期会出现在列表中的其他位置(因此,并非您期望的顺序)
When I put ordering:true
2 of the 2016 dates appear somewhere else in the list (so, not in order you would expect)
一切都指向时刻,我认为我需要对此进行排序.但是我不确定如何.
With everything pointing at Moment I thought I needed to sort with that. But I'm not sure how.
我在某个地方看到了$.fn.dataTable.moment('DD.MM.YYYY');
,但是我知道fn
不再适用于最新版本的数据表吗?
I saw $.fn.dataTable.moment('DD.MM.YYYY');
somewhere, but I understood that the fn
doesn't work with this newest version of datatables anymore?
有人知道如何对日期进行排序吗?
Anyone knows how to sort dates?
推荐答案
使用 date-eu
排序插件,以DD/MM/YY
格式对日期进行排序.
Use date-eu
sorting plugin to sort dates in the format DD/MM/YY
.
包括以下JS文件//cdn.datatables.net/plug-ins/1.10.11/sorting/date-eu.js
并使用以下代码:
Include the following JS file //cdn.datatables.net/plug-ins/1.10.11/sorting/date-eu.js
and use the code below:
var historiektable = $('#dataTableHistoriek').DataTable({
"paging" : false,
"ordering" : true,
"scrollCollapse" : true,
"searching" : false,
"columnDefs" : [{"targets":3, "type":"date-eu"}],
"bInfo": true
});
这篇关于数据表中的排序日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!