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

Select node on right click

3 Answers 447 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Gregory
Top achievements
Rank 1
Gregory asked on 23 Oct 2017, 07:25 PM

How can we select the node that is clicked on by a right click event?  I am trying to pass the selected node's id on a context menu select event but unless the user left clicks on the node to select it first, the last selected node information gets sent, if one was even selected.

This may be fairly basic, but I can't find any examples of this.

Thanks.

3 Answers, 1 is accepted

Sort by
0
Neli
Telerik team
answered on 24 Oct 2017, 01:26 PM
Hi Gregory,

The following article from our documentation shows how the ContextMenu could be implemented on the right click event of the TreeView widget. 

As it is shown in the example, on the select event of the ContextMenu the node data could be get by using TreeView dataItem method.
var nodeData = $("#treeview").data("kendoTreeView").dataItem(node);

Regards,
Neli
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Gregory
Top achievements
Rank 1
answered on 24 Oct 2017, 03:39 PM

Thank you for the reply.

This doesn't seem to give me the node that the context menu / right click event was taken on.  $(e.target) in the onSelect event of the context menu returns the entire treeview.

    function cmResourceActions_onSelect(e) {
        var tvDependencyViewer = $("#tvDependencyViewer").data("kendoTreeView");
        alert($(e.target).text());

....

 

0
Neli
Telerik team
answered on 25 Oct 2017, 10:43 AM
Hi Gregory,

$(e.target) is returning the selected node as an jQuery object. To get the data of the node, the dataItem method should be used.
select: function(e) {           
var node = $(e.target);  
// you can get the node data (e.g. id) via the TreeView dataItem method:
var nodeData = $("#treeview").data("kendoTreeView").dataItem(node);
}

I made a simple Dojo based on the article I have sent previously. On selecting an item form the ContextMenu, the node from the TreeView and its  data are console logged.

This could be observed also on the linked screencast.

Regards,
Neli
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
TreeView
Asked by
Gregory
Top achievements
Rank 1
Answers by
Neli
Telerik team
Gregory
Top achievements
Rank 1
Share this question
or