add
事件在单击kendoGridToolbarTemplate
下的kendoGridAddCommand
时触发。
HTML :
<kendo-grid
(add)="addHandler($event)"
>
<ng-template kendoGridToolbarTemplate>
<button kendoGridAddCommand>Add new</button>
</ng-template>
<kendo-grid-column field="id" title="ID" width="120"></kendo-grid-column>
<kendo-grid-column field="name" title="name" width="120"></kendo-grid-column>
</kendo-grid>
TS :
protected addHandler({sender}) {
// define all editable fields validators and default values
const group = new FormGroup({
'id': new FormControl(),
'name': new FormControl()
});
// show the new row editor, with the `FormGroup` build above
sender.addRow(group);
}
需求
在组件init或网格外部触发加法事件。默认情况下,一行应与窗体控件一起显示,而无需单击Add new
按钮。
我尝试了下面提供的解决方案,但没有成功。
发布于 2018-09-17 12:37:13
您可以处理AfterViewInit事件,并调用网格addRow法,例如:
ngAfterViewInit() {
this.formGroup = new FormGroup({
'ProductID': new FormControl(),
'ProductName': new FormControl('', Validators.required),
'UnitPrice': new FormControl(0),
'UnitsInStock': new FormControl('', Validators.compose([Validators.required, Validators.pattern('^[0-9]{1,3}')])),
'Discontinued': new FormControl(false)
});
this.grid.addRow(this.formGroup);
}
https://stackoverflow.com/questions/52364301
复制相似问题