We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Right Click Select and Context Menu

Hi,

I have a diagram with blocks and links.

I want the user to be able to right click on a node and and display a context menu, with items specific to that node.

Is it possible to know exactly what has been clicked on entirely on the client side, without a postback?

Also is there a way to select an block (or node) from the client side, by the right click.

Thanks,

Pete


1 Reply

RS Rajarajeswari S Syncfusion Team November 21, 2007 02:45 PM UTC


Hi Peter,

1. I want the user to be able to right click on a node and display a context menu?

You can have the context menu by right clicking the node. To display the context menu on the selected node and to add new nodes, following JavaScript is used.

// To display the contextmenu
function attachevent()
{
document.getElementById(''DiagramWebControl1'').oncontextmenu=function()
{
PosX = ConvertXYToDocument( Diagram.GetRootElement(), event.clientX, event.clientY, Diagram.GetMagnification() ).x;
PosY = ConvertXYToDocument( Diagram.GetRootElement(), event.clientX, event.clientY, Diagram.GetMagnification() ).y;
Popup.ShowPopup(event.clientX, event.clientY);
return false;
};
}
function OnContextMenuClick(Obj)
{
if(Obj.Text!="Edit")
{
Diagram.Refresh(Obj.Text+"|"+PosX+''|''+PosY);
}
else if(IsNodeSelected)
{
alert(''Not implemented'')
}
else
{
alert("Please select a Node to Edit");
}
return false;
}

2. Is it possible to know exactly what has been clicked on entirely on the client side, without a postback?

Yes, It is possible. From the client side itself you can get the item on which you have clicked.

if(Obj.Text!="Edit")
{
Diagram.Refresh(Obj.Text+"|"+PosX+''|''+PosY);
}
else if(IsNodeSelected)
{
alert(''Not implemented'')
}
Here you are getting the item text using "Obj.Text".


3. Also is there a way to select an block (or node) from the client side, by the right click.

Yes it is also possible. Please refer the below code which illustrates this:

PosX = ConvertXYToDocument( Diagram.GetRootElement(), event.clientX, event.clientY, Diagram.GetMagnification() ).x;
PosY = ConvertXYToDocument( Diagram.GetRootElement(), event.clientX, event.clientY, Diagram.GetMagnification() ).y;

Please refer the sample from the below link:

http://websamples.syncfusion.com/samples/Diagram.Web/5.2.0.25/F69957/main.htm

Please let me know if this helps you out.

Regards,
Raji



Loader.
Live Chat Icon For mobile
Up arrow icon