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

How to disable contextmenu except in the grid row?

2 Answers 146 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
Tom
Top achievements
Rank 1
Tom asked on 23 Jul 2009, 05:06 PM

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 Answers, 1 is accepted

Sort by
0
Tom
Top achievements
Rank 1
answered on 24 Jul 2009, 03:41 PM
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?
0
Lini
Telerik team
answered on 27 Jul 2009, 07:13 AM
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.
Tags
FileExplorer
Asked by
Tom
Top achievements
Rank 1
Answers by
Tom
Top achievements
Rank 1
Lini
Telerik team
Share this question
or