数据表中日期时间列的订购依据问题

时间:2018-08-20 10:27:21

标签: datetime datatables

我的表中有一列包含日期时间对象的列。我正在使用数据表插件。 在尝试对特定列进行排序时,它会被排序并带有错误。例如,以下日期

Aug. 20, 2018, 11:16 a.m.  
Aug. 2, 2018, 12:25 p.m. 
Aug. 4, 2018, 3:03 p.m. 

我得到的排序结果为

Aug. 2, 2018, 12:25 p.m.  
Aug. 20, 2018, 11:16 a.m.  
Aug. 4, 2018, 3:03 p.m.  

该如何纠正?

1 个答案:

答案 0 :(得分:0)

jquery official document中所述,您只能对提及格式的数据进行排序。

并对日期或时间进行排序,您可以添加以下行以对日期或时间进行排序:

$('#example').dataTable( {
     columnDefs: [
       { type: 'date-uk', targets: 0 }
     ]
  } );

0是列的索引。您可以根据列索引进行修改。 如果您以相同格式接收数据,则可以将date-uk类型更改为文档中提到的任何其他类型。