How to disable contextmenu except in the grid row?

3 posts, 0 answers
  1. Tom
    Tom avatar
    13 posts
    Member since:
    Jul 2012

    Posted 23 Jul 2009 Link to this post

    I tried to disable unnecessary context menu when I set a grid with ContextMenus. By default, if you click the blank part of the grid, it disables the Delete menu.

    However, after adding customized menu like Download, it shows in the context menu even there is no selected item (i.e., How can I download it?). So I want to disable the unnecessary menu or make it invisible except in the grid row context menu.

  2. Tom
    Tom avatar
    13 posts
    Member since:
    Jul 2012

    Posted 24 Jul 2009 Link to this post

    I solved the problem partially using the fllowing codes from http://stackoverflow.com/questions/1173202/how-to-disable-contextmenu-except-in-the-grid-of-telerik-fileexplorer

    <script type="text/javascript">
    function OnClientLoad(explorer)
    {
            explorer
    .get_gridContextMenu().add_showing(disableItem);
    }
    function disableItem(sender, args)
    {
           
    var target = args.get_targetElement();
           
    if (target && target.className == "rgDataDiv")
           
    {
                   
    var dlItem = sender.findItemByValue("download");
                    dlItem
    .set_enabled(false);
           
    }
    }
    </
    script>
    <
    telerik:RadFileExplorer runat="server" ID="RadFileExplorer1" OnClientLoad="OnClientLoad"></telerik:RadFileExplorer>

    However, I still have an enabled menu in the header context menu. What is the working className or soultion for Header Context Menu?
  3. Lini
    Admin
    Lini avatar
    2144 posts

    Posted 27 Jul 2009 Link to this post

    Hi,

    The solution you have is almost complete. You just need to handle more specific cases in the disableItem() function.

    function disableItem(sender, args) 
        var target = args.get_targetElement(); 
        var isOverRow = false
        if (target) 
        { 
            if (Sys.UI.DomElement.containsCssClass(target, "rfeFileExtension") ||  
                (target.tagName.toLowerCase() == "td" && !target.className)) 
                isOverRow = true
        } 
         
        if (!isOverRow) 
        { 
            //disable new item 
            var dlItem = sender.findItemByValue("download"); 
            dlItem.set_enabled(false); 
        } 

    Here is the updated code. It checks only if the click was over a grid row. Everywhere else it will disable the custom menu item.

    Kind regards,
    Lini
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top