KendoUI Angular Grid外部命令

问题描述 投票:1回答:1

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

谢谢

angular kendo-ui kendo-ui-grid
1个回答
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

© www.soinside.com 2019 - 2024. All rights reserved.