Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Row click event on Kendo-angular2-grid

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);
  });
}
like image 363
indra257 Avatar asked May 04 '17 14:05

indra257


1 Answers

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);
 }
like image 108
narasak.man Avatar answered Nov 10 '22 12:11

narasak.man