手写表格中的日期排列

问题描述 投票:1回答:1

我在我的angular项目中使用handson table lib.有一个日期列,我想在表的初始化时将日期格式化为DDMMYYYY,但不幸的是什么都没有发生,甚至当我在angular的hooks中调用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个回答
0
投票

嗨,你有使自定义单元格渲染你的日期单元。

 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;
      }
    },
  ],
© www.soinside.com 2019 - 2024. All rights reserved.