KendoUI Angular Grid外部命令

时间:2018-01-17 14:58:43

标签: angular kendo-ui kendo-ui-grid

我在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})**
}

THX

1 个答案:

答案 0 :(得分:0)

烨!网格是一个组件。你只需要一个参考。

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