ContextMenu for whole tree

4 posts, 0 answers
  1. Igor
    Igor avatar
    3 posts
    Member since:
    Apr 2015

    Posted 07 Apr 2015 Link to this post

    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?

  2. Ivan Danchev
    Admin
    Ivan Danchev avatar
    829 posts

    Posted 09 Apr 2015 Link to this post

    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.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Igor
    Igor avatar
    2 posts
    Member since:
    Apr 2015

    Posted 09 Apr 2015 in reply to Ivan Danchev Link to this post

    Ivan, thank you for your answer.

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

  5. Ivan Danchev
    Admin
    Ivan Danchev avatar
    829 posts

    Posted 10 Apr 2015 Link to this post

    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.

     
Back to Top