ngHandsontable:日期格式在热列指令中不起作用

ngHandsontable: date-format not working in hot-column directive

我尝试使用 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>

日期列不会格式化。其他类型的格式,例如严重性列中使用 format 属性的 numeric 类型正在工作。

完成table代码:

  <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() 格式化日期。

根据https://github.com/handsontable/ngHandsontable/issues/178上的回答:

Hi @mathiasconradt, unfortunately date-format doesn't work in the same manner than format (for numbers). This issue is related with Handsontable itself and you can track changes here.

Workaround for this issue is call validateCells method after table initialization. It forces the correction date format to another. I've created demo here.

在视图中使用on-after-init

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

  this.onAfterInit = function() {
    this.validateCells();
  }

在控制器中。