数据表:日期/时间排序插件未排序 [英] Datatable: date / time sorting plug-in not ordering
本文介绍了数据表:日期/时间排序插件未排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个基本的SpringBoot应用程序,嵌入式Tomcat,Thymeleaf模板引擎 我想订购数据表的1个日期列.
I have a basic SpringBoot app., embedded Tomcat, Thymeleaf template engine I want to order 1 date column of a datatable.
在我的POJO中:
public String getTimeFormatted() {
DateTimeFormatter formatter =
DateTimeFormatter.ofPattern("EEEE, MMMM d,yyyy h:mm,a", Locale.ENGLISH);
LocalDateTime dateTime = LocalDateTime.ofEpochSecond(time, 0, ZoneOffset.UTC);
return dateTime.format(formatter);
}
在模板中:
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js"></script>
<script src="https://cdn.datatables.net/plug-ins/1.10.15/sorting/datetime-moment.js"></script>
<script th:inline="javascript">
$(document).ready(function() {
$.fn.dataTable.moment( 'EEEE, MMMM d,yyyy h:mm,a' );
$('#table').dataTable( {
"bLengthChange": false,
"pageLength": 25,
});
} );
</script>
,但订购不正确
推荐答案
这很容易调试.
我什至制作了一个简单示例.
您在代码中使用的格式为EEEE, MMMM d,yyyy h:mm,a
(我假设是在春季),但是您忘了将其转换为moment
格式...和
You are using a format as EEEE, MMMM d,yyyy h:mm,a
in your code (I assume in spring) but you forgot to translate that into moment
format... and from the docs, that should be: dddd, MMMM D,YYYY h:mm,a
所以代码实际上应该是:
so the code should actually be:
$.fn.dataTable.moment("dddd, MMMM D,YYYY h:mm,a");
这篇关于数据表:日期/时间排序插件未排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文