【问题标题】:Date formating in handson tableHandsontable中的日期格式
【发布时间】:2020-09-22 00:52:57
【问题描述】:

我在我的 Angular 项目中使用 handson table lib。有一个日期列,我希望日期在表的初始化时像 DD/MM/YYYY 那样格式化,但不幸的是,即使我在 Angular 的钩子中调用 afterRender()(在视图初始化之后和视图检查之后),也没有发生任何事情它告诉我不能渲染未定义,所以此时表未定义。 那么解决方案是什么? 这是 afterRender 方法

private afterRender( ) {
  console.log("rendere")
  this.hotRegisterer.getInstance(this.idTableau).render();
  this.hotRegisterer.getInstance(this.idTableau).validateCells();
}

这是我的设置

hotSettings: Handsontable.GridSettings = {
  height: MajStockComponent.HANDSON_TABLE_HEIGHT,
  width: MajStockComponent.HANDSON_TABLE_WIDTH,
  stretchH: 'all',
  rowHeaderWidth: MajStockComponent.HANDSON_TABLE_ROW_HEADER_WIDTH,
  colWidths: MajStockComponent.HANDSON_TABLE_COL_WIDTH,
  colHeaders: MajStockComponent.HANDSON_TABLE_IS_COL_HEADER,
  licenseKey: ConstantesNuc.LICENCE_KEY_TABLE_HANDSOME_TABLE,
  language: ConstantesNuc.HANDSOME_FR,
  columns: [
    {
      data: "code",
      type: 'text',
      readOnly: true
    },
    {
      data: "num",
      type: 'text',
      readOnly: true
    },
    {
      data: "date",
      type: 'date',
      readOnly: true,
      dateFormat: 'DD/MM/YYYY',
      correctFormat: true,
    },
  ],
  nestedHeaders: [
    [{
      label: '',
      colspan: 3
    }],
    ['Code ', 'Num ', 'Date']
  ],
  afterLoadData: (bool) => {
    this.afterRender();
  },
}

【问题讨论】:

标签: javascript angular handsontable rhandsontable


【解决方案1】:

您好,您已经为您的日期单元格进行了自定义单元格渲染。

 columns: [
    {
      data: "code",
      type: 'text',
      readOnly: true
    },
    {
      data: "num",
      type: 'text',
      readOnly: true
    },
    {
      data: "date",
      type: 'date',
      readOnly: true,
      renderer: function(instance, td, row, col, prop, value, cellProperties) {
      dateCell = value,  // format your date value with custom pipe.
      return dateCell;
      }
    },
  ],

【讨论】:

  • 如果我要使用管道,它必须在构造函数中贴花,但我不能在渲染器中调用 this.datePipe
猜你喜欢
  • 2018-01-24
  • 2017-03-30
  • 2017-06-28
  • 2015-10-11
  • 2013-05-16
  • 2018-01-28
  • 2010-11-03
  • 2017-12-17
  • 1970-01-01
相关资源
最近更新 更多