Below is the grid that I have developed using Kendo-Angular2. I need a click event on the row and in the event I need the row information. I wrote a general click event and tried o get the row information, but it doesn't work if I go to second page in the pagination. Is there a simple row click event that gives the row information.
plnkr: http://plnkr.co/edit/h0fVaP4NykRiILA7dyHn?p=preview
click event code:
ngAfterViewInit() {
this.renderer.listen(this.gridRef.nativeElement, "mousedown", (event) => {
if (!event.target.matches('tbody>tr *')) {
return;
}
const gridData = this.grid.data;
const tr = event.target.closest('tr');
const dataItem = gridData.data[tr.rowIndex + this.grid.skip];
console.log(dataItem);
});
}
Angular Template
<kendo-grid #gridUser
[kendoGridBinding]="gridData"
[pageSize]="10"
[pageable]="true"
[sortable]="true"
[selectable]="true"
(selectionChange)="gridUserSelectionChange(gridUser, $event)">
<kendo-grid-column field="name" title="ID">
</kendo-grid-column>
<kendo-grid-column field="nameThai" title="Name">
</kendo-grid-column>
<kendo-grid-pdf fileName="User.pdf"></kendo-grid-pdf>
<kendo-grid-excel fileName="User.xlsx"></kendo-grid-excel>
</kendo-grid>
Angular Component
gridUserSelectionChange(gridUser, selection) {
// let selectedData = gridUser.data.data[selection.index];
const selectedData = selection.selectedRows[0].dataItem;
console.log(selectedData);
}
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