tags:

views:

664

answers:

1

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.

I'm using telerik ASP.NET AJAX contorl 2009 Q2.

Thanks in advance.

+1  A: 

This piece of code should help - basically what you need to do is attach a handler to the menu showing event, check the target element (the element where you right-clicked) and if it is the grid area itself - disable the menu item.

<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>
lingvomir
Great solution! However, I still have enabled item in the header context menu.
Sanghoon
You just need to add some more checks in the disableItem() function. This code only checks for the empty area of the grid. header/footer are different items so the the menu item will not be disabled there unless there are some more IFs :)
lingvomir