0

我尝试格式化日期列,如下所示,settings以及date-format直接属性。两者都不起作用。列类型设置为date,提供的数据类型为datengHandsontable:日期格式在热列指令中不起作用

<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> 

日期列将不会格式化。其他类型的格式,例如使用format-attributes的Severity列中的numeric类型正在工作。

enter image description here

完整的表码:

<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。

遗憾的是,没有一个demo可用,使用date-format属性。

我目前的解决方法是使用自定义渲染器,并通过moment()在那里格式化日期。

+0

在这里创建一张票:https://github.com/handsontable/ngHandsontable/issues/178 –

回答

0

据对https://github.com/handsontable/ngHandsontable/issues/178答案:

嗨@mathiasconradt,不幸的是日期格式不一样 方式不是格式作品(数字)。此问题与 Handsontable本身有关,您可以跟踪更改here

此问题的解决方法是在初始化表 初始化后调用validateCells方法。它强制更正日期格式为另一个。我已经创建了 演示here

使用on-after-init在视图中:

<hot-table col-headers="true" datarows="ctrl.data" on-after-init="ctrl.onAfterInit"> 

this.onAfterInit = function() { 
    this.validateCells(); 
    } 
在控制器