我在Angular(5)应用程序中使用KendoUI-Grid。
HTML:
<kendo-grid [data]="GRIDData"
(add)="addHandler($event)">
<ng-template kendoGridToolbarTemplate>
<button kendoGridAddCommand type="button">Add new</button>
</ng-template>
零件:
public addHandler({sender}) {
this.formGroup = createFormGroup({
'Id': 'NEW',
'Name': 'New entry'
});
sender.addRow(this.formGroup);
}
是否可以从网格外部触发addCommand(或任何其他)?也许是这样的:
HTML:
<button (click)="gridAddRow()"> Add New Row to Grid</button>
comnponent;
gridAddRow() {
**//calling addHandler ({sender})**
}
谢谢
对!网格是一个组件。你只需要一个参考。
HTML:
<kendo-grid [data]="GRIDData"
(add)="addHandler($event)">
<ng-template kendoGridToolbarTemplate>
<button kendoGridAddCommand type="button">Add new</button>
</ng-template>
零件:
@ViewChild(GridComponent) private grid: GridComponent;
gridAddRow() {
**//calling addHandler ({sender})**
this.grid.addRow(** your form group goes here **)
}
stackblitz https://stackblitz.com/edit/angular-ruohgs