'Execute [kendoGridAddCommand] on component init
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.
Solution 1:[1]
You can handle the AfterViewInit event, and call the Grid addRow method, e.g.:
ngAfterViewInit() {
this.formGroup = new FormGroup({
'ProductID': new FormControl(),
'ProductName': new FormControl('', Validators.required),
'UnitPrice': new FormControl(0),
'UnitsInStock': new FormControl('', Validators.compose([Validators.required, Validators.pattern('^[0-9]{1,3}')])),
'Discontinued': new FormControl(false)
});
this.grid.addRow(this.formGroup);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | topalkata |
