我尝试用settings和直接date-format属性格式化日期列,如下所示。这两样都不管用。列类型设置为date,所提供的数据为date类型。
<hot-column data="createdAt" title="'Date'" type="'date'"
settings="{dateFormat:'DD/MM/YYYY', type: 'date'}"
date-format="'DD/MM/YYYY'"
correct-format="true"
allow-empty="true" read-only></hot-column>日期列只是不格式化。其他类型的格式设置(如使用numeric -attribute的严重性列中的format类型)正在工作。

完整的表格代码:
<hot-table read-only datarows="events" class="table table-bordered table-striped" row-headers="false" manual-column-resize="true">
<hot-column data="createdAt" title="'Date'" type="'date'"
settings="{dateFormat:'DD/MM/YYYY', type: 'date'}"
date-format="'DD/MM/YYYY'"
correct-format="true"
allow-empty="true" read-only></hot-column>
<hot-column data="eventType" title="'Event Type'"></hot-column>
<hot-column data="user.displayName" title="'User'"></hot-column>
<hot-column data="ipAddress" title="'IP Address'"></hot-column>
<hot-column data="severity" title="'Severity'" type="'numeric'" format="'$ 0,0.00'"></hot-column>
<hot-column data="eventMessage" title="'Message'"></hot-column>
<hot-column data="" title="'Old data'"></hot-column>
<hot-column data="" title="'New data'"></hot-column>
</hot-table>使用ngHandsontable 0.12.0,Handsontable 0.26.1。
不幸的是,没有一个使用演示属性的date-format可用。
我目前的解决办法是使用自定义呈现程序,并通过moment()格式化日期。
发布于 2016-09-01 08:05:10
根据https://github.com/handsontable/ngHandsontable/issues/178上的答案
嗨@mathiasconradt,不幸的是,日期格式的工作方式与格式不同(对于数字)。此问题与Handsontable本身有关,您可以跟踪更改这里。 解决此问题的方法是在表初始化后调用validateCells方法。它强制更正日期格式为另一个格式。我创建了演示这里。
在视图中使用on-after-init:
<hot-table col-headers="true" datarows="ctrl.data" on-after-init="ctrl.onAfterInit">和
this.onAfterInit = function() {
this.validateCells();
}在控制器里。
https://stackoverflow.com/questions/39052001
复制相似问题