Select grid row item from code

2019-07-26 22:46发布

问题:

Is there any way to select a grid row from code so you can trigger the selectionChange event emitter? I don't know how to get hold of the grid component and execute the event manually.

Selection grid sample plunkr

<kendo-grid [data]="gridView" [selectable]="true"></kendo-grid>

--

Edit: If I access the grid manually by adding a #gridReference tag into the kendo-grid tag, I can access the component using

@ViewChild('activityGrid') gridReference: GridComponent;

But when executing

var selectionEvent = { index: 0, selected: false } as SelectionEvent;  
this.gridReference.selectionChange.emit(selectionEvent);

It still doesn't work. It migth work when I have to access the SelectionService using unselect but that's a private class.

Updated plunkr

回答1:

Unfortunately, currently it is not possible to select a row programmatically via the public API.

The selectionChange emitter is there to trigger the selectionChange event and I'm afraid it will not trigger the selection logic.



回答2:

This could be achieved now by utilizing the new SelectionDirective. It allows specifying the key to be stored when selecting a row and also the selectedKeys collection to hold reference to the selected keys. This also allows to programatically modify the selection.