The add
event fires when the kendoGridAddCommand
under kendoGridToolbarTemplate
is clicked.
HTML :
<kendo-grid
(add)="addHandler($event)"
>
<ng-template kendoGridToolbarTemplate>
<button kendoGridAddCommand>Add new</button>
</ng-template>
<kendo-grid-column field="id" title="ID" width="120"></kendo-grid-column>
<kendo-grid-column field="name" title="name" width="120"></kendo-grid-column>
</kendo-grid>
TS :
protected addHandler({sender}) {
// define all editable fields validators and default values
const group = new FormGroup({
'id': new FormControl(),
'name': new FormControl()
});
// show the new row editor, with the `FormGroup` build above
sender.addRow(group);
}
Requirement
Trigger the addrow event on component init or outside the Grid. By default one row should display with the form controls without click on Add new
button.
I tried the below solution provided in SO but did not get success.
You can handle the AfterViewInit event, and call the Grid addRow method, e.g.:
EXAMPLE