KendoUI Angular Grid external command

瘦欲@ 提交于 2020-01-06 03:45:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!