This is a migrated thread and some comments may be shown as answers.

Example of using selectBy (context: { dataItem: any; index: string; }) => any

1 Answer 74 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Andy asked on 07 May 2019, 04:09 PM
Is there an example somewhere of using the selectBy so that the selectionChange event handler is passed a dataItem (or context.dataItem)? I have seen this capability alluded to in some articles, but I have not been able to find examples or get it to work for me. Thank you.

1 Answer, 1 is accepted

Sort by
0
Dimiter Topalov
Telerik team
answered on 08 May 2019, 11:11 AM
Hello Andy,

The selectionChange event handler contains the information about the data item and its index out-of-the-box:

https://www.telerik.com/kendo-angular-ui/components/treeview/selection/#toc-modifying-the-selection

... whereas the selectBy input of the SelectDirective requires a callback that will determine what data item key (usually ID) will be stored in the selectedKeys collection:

https://www.telerik.com/kendo-angular-ui/components/treeview/api/SelectDirective/

You can also make the callback return the whole data item, and this way the whole items will be store in the selectedKeys collection, e.g.:

https://stackblitz.com/edit/angular-cxbwjf?file=app/app.component.ts

I hope this helps, but if I am missing something, please send us some further details and context about the scenario and the goal that you are after, as well as what exactly does not work for you, so I can try providing a suggestion that is most suitable to the specific use case. Thank you in advance.

Regards,
Dimiter Topalov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
TreeView
Asked by
Andy
Top achievements
Rank 1
Answers by
Dimiter Topalov
Telerik team
Share this question
or