如何在 angular 2+ 中为 handsontable 添加自定义验证
How to add custom validations for handsontable in angular 2+
我在 angular 6.
中使用 handsontable
我尝试了添加自定义验证的代码,该代码显示在我的 angular 6 组件的官方文档中,但没有成功。
我搜索了几个网站,但没有找到任何一个示例来说明如何在 angular 2+ 版本的 handsOntable
中添加自定义验证
谁能告诉我如何在 angular 2+ 版本
中注册自定义验证
提前致谢:)
为电子邮件创建了示例自定义验证器并能够设置为一列
emailValidator = (value, callback) => {
console.log(value)
setTimeout(function(){
if (/.+@.+/.test(value)) {
callback(true);
}
else {
callback(false);
}
}, 1000);
};
private columns: any[] = [
{
data: 'name'
},
{
data: 'email',
validator: this.emailValidator,
// Uncomment below line accept invalid input and indicate
// allowInvalid: true
}
];
@ViewChild(HotTableComponent) hotTableComponent;
// Call validator after initialization
afterInit() { this.hotTableComponent.getHandsontableInstance().validateCells(function(valid){});
afterInit 是一个事件发射器
<hot-table [data]="data"
[colHeaders]="colHeaders"
[columns]="columns"
[options]="options"
(hotInstanceCreated)="instanceCreated($event)"
(afterInit)="afterInit(event$)"
[colWidths]="colWidths">
https://stackblitz.com/edit/angular-kjmvq4?file=app%2Fapp.component.ts
我在 angular 6.
中使用 handsontable我尝试了添加自定义验证的代码,该代码显示在我的 angular 6 组件的官方文档中,但没有成功。
我搜索了几个网站,但没有找到任何一个示例来说明如何在 angular 2+ 版本的 handsOntable
中添加自定义验证谁能告诉我如何在 angular 2+ 版本
中注册自定义验证提前致谢:)
为电子邮件创建了示例自定义验证器并能够设置为一列
emailValidator = (value, callback) => {
console.log(value)
setTimeout(function(){
if (/.+@.+/.test(value)) {
callback(true);
}
else {
callback(false);
}
}, 1000);
};
private columns: any[] = [
{
data: 'name'
},
{
data: 'email',
validator: this.emailValidator,
// Uncomment below line accept invalid input and indicate
// allowInvalid: true
}
];
@ViewChild(HotTableComponent) hotTableComponent;
// Call validator after initialization
afterInit() { this.hotTableComponent.getHandsontableInstance().validateCells(function(valid){});
afterInit 是一个事件发射器
<hot-table [data]="data"
[colHeaders]="colHeaders"
[columns]="columns"
[options]="options"
(hotInstanceCreated)="instanceCreated($event)"
(afterInit)="afterInit(event$)"
[colWidths]="colWidths">
https://stackblitz.com/edit/angular-kjmvq4?file=app%2Fapp.component.ts