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

ContextMenu for whole tree

3 Answers 46 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Igor
Top achievements
Rank 1
Igor asked on 07 Apr 2015, 03:20 PM

Hi!

I need to make context menu for whole tree. I have context menues for nodes. I need to have context menu in case of user clicking on tree and not on some node. How to make it?

3 Answers, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 09 Apr 2015, 03:39 PM
Hello,

The RadTreeViewContextMenu is associated with the RadTreeNodes and so are the events that make the ContextMenu appear on Node click. If you don't want the ContextMenu to show only when the user clicks on a particular node this can be done by subscribing to the OnClientContextMenuShowing event and canceling it if the user has clicked on any node, except the one you specify:
function ClientContextMenuShowing(sender, eventArgs) {
        var node = eventArgs.get_node();
        if (node.get_text() != "Search") {
            eventArgs.set_cancel(true);
        }
    }

<telerik:RadTreeView ID="RadTreeView1" runat="server" OnClientContextMenuShowing="ClientContextMenuShowing">

The sample code above would allow the menu to show only if the user clicks on a node with text "Search".

Regards,
Ivan Danchev
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Igor
Top achievements
Rank 1
answered on 09 Apr 2015, 05:36 PM

Ivan, thank you for your answer.

 Is there any wat to show context menu then user click on tree, but not on node?

0
Ivan Danchev
Telerik team
answered on 10 Apr 2015, 03:07 PM
Hello,

If by "tree" you mean the connection lines that link the Nodes, showing the RadContenxtMenu can be triggered by clicking on the <div> element that wraps the connection line, but clicking on the Node would open the menu as well, because the <span> element that corresponds to that Node is part of the <div> element. 
<telerik:RadContextMenu ID="RadContextMenu1" runat="server">
    <Items>
        <telerik:RadMenuItem Text="Trees" />
        <telerik:RadMenuItem Text="Sunset" />
        <telerik:RadMenuItem Text="Mountains" />
    </Items>
</telerik:RadContextMenu>
 
<script>
    var $ = $telerik.$;
 
    $(".rtTop").click(function () {
        showMenu(event);
    });
 
    $(".rtMid").click(function () {
        showMenu(event);
    });
 
    $(".rtBot").click(function () {
        showMenu(event);
    });
 
    function showMenu(e) {
        var contextMenu = $find("<%= RadContextMenu1.ClientID %>");
        contextMenu.show(e);
    }
</script>

Regards,
Ivan Danchev
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
TreeView
Asked by
Igor
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Igor
Top achievements
Rank 1
Share this question
or