我在我的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();
},
}
嗨,你有使自定义单元格渲染你的日期单元。
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;
}
},
],