Select grid row item from code

主宰稳场 提交于 2019-12-11 05:35:19

问题


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.



来源:https://stackoverflow.com/questions/39957861/select-grid-row-item-from-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!