问题
i'm using KendoUI-Grid in an Angular (5) app.
html:
<kendo-grid [data]="GRIDData"
(add)="addHandler($event)">
<ng-template kendoGridToolbarTemplate>
<button kendoGridAddCommand type="button">Add new</button>
</ng-template>
component:
public addHandler({sender}) {
this.formGroup = createFormGroup({
'Id': 'NEW',
'Name': 'New entry'
});
sender.addRow(this.formGroup);
}
Is it possible to trigger the addCommand (or any other) from outside the grid? Perhaps something like:
html:
<button (click)="gridAddRow()"> Add New Row to Grid</button>
comnponent:
gridAddRow() {
**//calling addHandler ({sender})**
}
THX
回答1:
Yup! the grid is a component. You just need a reference to it.
HTML:
<kendo-grid [data]="GRIDData"
(add)="addHandler($event)">
<ng-template kendoGridToolbarTemplate>
<button kendoGridAddCommand type="button">Add new</button>
</ng-template>
Component:
@ViewChild(GridComponent) private grid: GridComponent;
gridAddRow() {
**//calling addHandler ({sender})**
this.grid.addRow(** your form group goes here **)
}
stackblitz https://stackblitz.com/edit/angular-ruohgs
来源:https://stackoverflow.com/questions/48303995/kendoui-angular-grid-external-command