RadTreeView Multiple ContextMenu Get Active Menu Clicked Client Side

3 posts, 1 answers
  1. Scott
    Scott avatar
    9 posts
    Member since:
    Aug 2012

    Posted 08 Oct 2009 Link to this post

    I have 3 context menus loaded into my RadTreeView. I associate different menus with my nodes depending on node level. I'm using the OnClientContextMenuItemClicking event to prompt for Delete confirmation when user clicks a delete context menu command.  In my Client-side event handler, I want to determine which context menu was clicked so that I can hide just that menu.  I've found one way, but it seems cumbersome and subject to change if Telerik changes ID naming conventions.  Is there a better way to find the context menu that was clicked?  Here is what I have working right now:

    <script type="text/javascript">
       function contextMenuItemClicking(sender, eventArgs) {
           var item = eventArgs.get_menuItem();
           if (item.get_text() == "Delete") {
               if (!confirm("Confirm delete")) {
                   eventArgs.set_cancel(true);
                   for (var i = 0; i < sender.get_contextMenus().length; i++) {
                       if (sender.get_contextMenus()[i]._clientStateFieldID ==
                           eventArgs.get_node()._resolvedContextMenuID + "_ClientState") {
                           sender.get_contextMenus()[i].hide();
                           break;
                       }
                   }
               }
           } 
       }

    (...)

                <telerik:RadTreeView ID="radTreeMainView" Runat="server" 
                    Height="420px" 
                    Skin="Web20" 
                    OnClientContextMenuItemClicking="contextMenuItemClicking" 
                    oncontextmenuitemclick="radTreeMainView_ContextMenuItemClick"
                    >
                </telerik:RadTreeView>

  2. Answer
    Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 12 Oct 2009 Link to this post

    Hi Kevin Broughton,

    You can find the menu by using the following code:

    var menu = item.get_menu();
    var id = menu.get_id();


    Let me know if this helps.

    Regards,
    Veselin Vasilev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Scott
    Scott avatar
    9 posts
    Member since:
    Aug 2012

    Posted 12 Oct 2009 Link to this post

    Well, that was easy!  Yes, exactly what I was looking for.  Now I can simply do,
     

     

    (...)  
    eventArgs.set_cancel(true);  
    item.get_menu().hide(); 

    Thank you.

     

     

     

Back to Top