【问题标题】:Formatting Joda LocalDate in JqGrid在 JqGrid 中格式化 Joda LocalDate
【发布时间】:2017-07-13 13:29:26
【问题描述】:

我正在尝试在我的 jqGrid 中转换 jodaDateFormat。

我的 Entity 类中的声明是:

@Type(type="org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
@DateTimeFormat(iso=ISO.DATE)
@Column(nullable=false)
private LocalDate dateStart;

为了在视图中看到这个日期,我尝试在 tagx 文件中插入这个 javascript 转换:

<script type="text/javascript">
<![CDATA[
jodaLDFormatter = function (cellValue, options) {
    if(cellValue) {
        return $.datepicker.formatDate(
            'dd/MM/yyyy', 
            new Date(cellValue['year'], 
                    cellValue['monthOfYear']-1, 
                    cellValue['dayOfMonth']));
    } else {
        return '';
    }
};

在JSP页面中我是这样声明列的:

<table:jqcolumn id="l_list_dateStart" property="dateStart" formatter="jodaLDFormatter"/>

但我得到了这个:(来自页面来源)

<td role="gridcell" style="" title="NaN/NaN/NaNNaN" aria-describedby="l_list_dateStart">NaN/NaN/NaNNaN</td>

我不想转换字符串中的每个日期以便在 jqGrid 中看到它!

什么是正确的方法?!

【问题讨论】:

  • 您需要在 formatoptions 中设置 srcformat 和 newformat 选项。默认的 srcformat 是 ISO 日期 (Y-m-d)

标签: jsp datepicker jqgrid jodatime jsp-tags


【解决方案1】:

我认为您没有将 Joda 对象传递给视图。可能你从你的控制器发送一个向量,比如[day, month, year]

如果我的猜测是正确的,您可以将其添加到您的 colmodel

formatter: 'date', srcformat:'dd/mm/yy', date:'true'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-02-19
    • 2016-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-07
    • 2015-05-30
    相关资源
    最近更新 更多