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

grid context menu code

1 Answer 36 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
Albert Shenker asked on 02 Oct 2012, 05:38 PM

I recently found the following example on your site demonstrating the handling of the grid RowContextMenu event and showing the menu. http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandmenu/defaultcs.aspx?product=grid

This example included the RowContextMenu handler:

function GridRowContextMenuHandler(sender, eventArgs) {
             
            var menu = $find("<%= menuId.ClientId %>");
             
            var evt = eventArgs.get_domEvent();
 
            if (evt.target.tagName == "INPUT" || evt.target.tagName == "A") {
                return;
            }
 
            var rowIndex = eventArgs.get_itemIndexHierarchical();
            menu.show(evt);
 
            evt.cancelBubble = true;
                evt.returnValue = false;
 
                if (evt.stopPropagation) {
                    evt.stopPropagation();
                    evt.preventDefault();
                }
 
             
        }


I have some code which I have been using since way back in the Prometheus days and I'm trying to figure out if it is equivalent to what you show in your example. It seems this code is more concise. Is there any benefit or drawback to using what I have here?

function GridRowContextMenuHandler(sender, eventArgs) {
var menu = $find("<%= menuId.ClientId %>");
if ((!eventArgs.relatedTarget) || (!Telerik.Web.DomUtility.isDescendantOrSelf(menu.get_element(), eventArgs.relatedTarget))) {
menu.show(eventArgs)
}
$telerik.cancelRawEvent(eventArgs);
}


1 Answer, 1 is accepted

Sort by
0
Antonio Stoilkov
Telerik team
answered on 05 Oct 2012, 08:39 AM
Hi Albert,

The two code blocks logic is similar but the conditions if the context menu will be shown are different. In the code provided from the demo the context menu will not be shown when you right click on a HTML input or a element which your function is missing. Note that if you don not want to show the context menu when clicking the above mentioned elements you could update your code.

Regards,
Antonio Stoilkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
Answers by
Antonio Stoilkov
Telerik team
Share this question
or