Hi,
I am using WebDataTree with custom context menu not the WebDataMenu. So when I right click on Tree node, I get the custom context menu, but also getting default context menu. See my below JS code for right click on Node. After execute the args.set_cancel = true, the default context menu is being showing.
function nodeClick(tree, args) { var button = 1; if (args.get_browserEvent() != null) { button=parseInt(args.get_browserEvent().button); } //right click if (button == 2) { //call context menu on another page parent.showContextMenu(args); args.set_cancel = true; } }
Hello, Karthik.
Thank you for using our product. I hope that I will be able to help you with my answer.
The set_cancel() is a method and if you want to use it you need to pass value as parameter in order to work:
args.set_cancel(true)
However this is will not stop browser context menu from showing, because `NodeClick` event is not responsible for that. `NodeClick` event of the tree is listening to a native `click` event of the browser. There is a separate `oncontextmenu` event that is fired after the `click` one. And even you cancel the default `click` event, then `oncontextemenu` one will fire.
What I suggest is the following - when tree is initialized then attach `oncontextmenu` handler to tree body and cancel it. Tell me if this solution is appropriate for your case. I will wait for your feedback.
<ig:WebDataTree runat="server"> <ClientEvents Initialize="InitializeHandler" />
...
</ig:WebDataTree>
<script type="text/javascript">
function InitializeHandler(sender, args) { sender.get_element().addEventListener("contextmenu", function (event) { event.preventDefault(); }
</script>
I guess when WebDataMenu is used as context one, then it is doing this internally. As you already noted you are using your custom menu, so please try my suggestion. Thank you!
Best regards,
Nikolay Alipiev
Software Developer
Hi Nikolay,
Thank you very much ! It resolves my problem and its working now.
There is a minor syntax change added "});" after event.preventDefault();.
Also, the custom context menu rendering in another page. So I have handled default context menu right click event handling on that page too.
function InitializeHandler(sender, args) { sender.get_element().addEventListener("contextmenu", function (event) { event.preventDefault(); }); }
Thanks & Regards,
Karthik Thangavel.