In Kendo UI (beta) for Angular 2, how does one trigger an event when a specific row is selected? There are no directives or components for the rows themselves; therefore, a (click)="triggeredFunction()" can't work if there is no row element.
Here is my grid:
<kendo-grid [data]="gridData" [selectable]="true">
<kendo-grid-column field="ProductName">
<template kendoHeaderTemplate let-column let-columnIndex="columnIndex">
{{column.field}}({{columnIndex}})
</template>
</kendo-grid-column>
<kendo-grid-column field="ProductName">
<template kendoCellTemplate let-dataItem>
<kendo-dropdownlist [data]="listItems"></kendo-dropdownlist>
</template>
</kendo-grid-column>
</kendo-grid>
Here is my component:
@Component({
selector: "ultron",
styleUrls: [String("./ultron.component.less")],
templateUrl: "./ultron.component.html",
})
export class UltronComponent {
private gridData: any[] = [{
"ProductID": 1,
"ProductName": "Chai",
"UnitPrice": 18.0000,
"Discontinued": true,
}, {
"ProductID": 2,
"ProductName": "Chang",
"UnitPrice": 19.0000,
"Discontinued": false,
}
}];
private listItems: Array<string> = ["@", "$", "#", "%"];
public triggeredFunction(){ ... }
}
To select a row when the Grid is in single selection mode, use either of the following actions: Click the row, or. Select the checkbox of the row, or. Press Enter on the row (only when Keyboard Navigation is enabled).
Fired when the widget is bound to data from its data source. The event handler function context (available via the this keyword) will be set to the widget instance.
What You can do in Kendo Grid is providing a multi-selection mecanisme using ctrl button. So the user presses ctrl and then clicks on the rows that he wants to select (ctrl + left mouse click). If this is what you look for, here is a code sample: $("#rowSelection").
The option that you need to set is selectable
and the valid values are true
and false
as currently only single row selection is supported. So your grid should look like this
<kendo-grid
[data]="gridView"
[selectable]="true"
>
</kendo-grid>
For the event you need to attach a (selectionChange)
event handler. Here is a plunkr
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With