刷新Handsontable角4
我正在使用n2-handsontable角4为一个项目。当数据发生变化时,我似乎无法弄清楚如何刷新表格。我发现这个职位:刷新Handsontable角4
这似乎是我想要的,但我无法弄清楚如何访问handsontable对象。我最初的想法是使用#进行绑定,但它不按预期工作,它只是将'undefined'传递给函数。
component.html
<button class="btn btn-default" (click)="add(hot)">Add</button>
<hotTable [data]="_dataHot"
[colHeaders]="_columnHeadersHot"
[columns]="_columnsHot"
[options]="{contextMenu: true}"
#hot>
</hotTable>
component.ts
add(hot){
//do stuff
hot.render();
}
编辑:我可能会迫使一个做ngIf技巧渲染,但似乎并不像一个很好的解决方案。
我最初有同样的问题,并无法弄清楚如何访问渲染功能。在component.ts文件中使用以下行对我来说是个诀窍。
hot.getHandsontableInstance().render();
我不确定的是为什么通过#hot返回未定义给你。我在下面列出我的代码片段。
component.html
<hotTable
[data]="data"
(afterChange)="afterChange($event, hot)"
[colHeaders]="colHeaders"
[columns]="columns"
[options]="options"
[colWidths]="colWidths"
#hot>
</hotTable>
component.ts
private afterChange(e: any, hot) {
// some commands
hot.getHandsontableInstance().render();
}
您需要使用ViewChild
装饰器在代码中获取对hot
的引用。您可以将其存储在相同名称的变量中。现在
@ViewChild('hot') hot
可以为this.hot
在类访问该组件的实例。
感谢您的帮助,'ViewChild'是在方向上的步骤。看起来'render()'不是handtable组件的有效函数。有一个'getHandsontableInstance()'返回'render()'''handsontable'类,但是'getHandsontableInstance()'在尝试和使用时返回undefined。 – Calidus
我很笨,我没有意识到我需要使用#hot,并在使用@viewchild()时将对象传递给函数。谢谢! – Calidus