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

nodeselect client side

3 Answers 20 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Fit2Page
Top achievements
Rank 1
Iron
Veteran
Iron
Fit2Page asked on 10 Mar 2021, 09:57 AM

Hi,

 

I managed to tab through nodes with the arrow keys. Now I want to take an action client side when a node is focused.

This is used to page through a library of PDFs. I cannot find a client-side event which triggers when a node is selected.

Suggestions?

 

Marc

3 Answers, 1 is accepted

Sort by
0
Accepted
Vessy
Telerik team
answered on 11 Mar 2021, 04:22 PM

Hi Marc,

You can achieve the desired functionality by handling the jQuery keydown event of the TreeView element, getting the currently selected node in it.

For example, you can have a similar logic:

<script>
            var $ = $ || $telerik.$;

            function onTreeViewLoad() {
                $(".RadTreeView").keydown(handleNodeFocus);
            }
            function handleNodeFocus(e) {
                var keyCode = e.keyCode || e.which;

                //if up or down arrow is pressed
                if (keyCode == 38 || keyCode == 40) {
                    var tree = $find("RadTreeView1");
                    var selectedNode = tree.get_selectedNode();
                    //your action here
                }
            }
        </script>
 <telerik:RadTreeView RenderMode="Lightweight" ID="RadTreeView1"TabIndex="1" runat="server" OnClientLoad="onTreeViewLoad">
 <Nodes>
 <telerik:RadTreeNode runat="server" Text="My Node 1">
 <Nodes>
 <telerik:RadTreeNode runat="server" Text="Child Node">
 </telerik:RadTreeNode>
 </Nodes>
 </telerik:RadTreeNode>
 <telerik:RadTreeNode runat="server" Text="My Node 2">
 </telerik:RadTreeNode>
 <telerik:RadTreeNode runat="server" Text="My Node 3">
 </telerik:RadTreeNode>
 <telerik:RadTreeNode runat="server" Text="My Node 4">
 </telerik:RadTreeNode>
 <telerik:RadTreeNode runat="server" Text="My Node 5">
 </telerik:RadTreeNode>
 </Nodes>
 </telerik:RadTreeView>

Regards,
Vessy
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Fit2Page
Top achievements
Rank 1
Iron
Veteran
Iron
answered on 12 Mar 2021, 12:56 PM
Thanks Vessy, I managed to get it working!
0
Vessy
Telerik team
answered on 12 Mar 2021, 01:04 PM

Hi,

Nice to hear that, Marc! You are absolutely welcome :)

Regards,
Vessy
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
TreeView
Asked by
Fit2Page
Top achievements
Rank 1
Iron
Veteran
Iron
Answers by
Vessy
Telerik team
Fit2Page
Top achievements
Rank 1
Iron
Veteran
Iron
Share this question
or