Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger event when row is selected in a Kendo UI Grid (Angular 2)

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(){ ... }

}
like image 571
ed-tester Avatar asked Nov 30 '16 16:11

ed-tester


People also ask

How to highlight selected row in kendo Grid angular?

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).

What is Databound event in kendo grid?

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.

How do I select multiple rows in kendo grid?

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").


1 Answers

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

like image 119
knikolov Avatar answered Nov 15 '22 15:11

knikolov