After all, how do I get the properties of a node?

Hi there, when the user clicks on a diagram node (imageNode), I want to display its addInfo,

function diagramNetwork_Click(event) {
        if (event && event.element && event.element.name && event.elementType === "node") {
            document.getElementById("documentTitle").innerHTML = event.element.getUserData("addInfo.DocumentData");  

but either it fails or gets an empty string. I tried getAttribute too. Event.element.name works nicely. 

Also, this works, but only on the second click:
            event.element.borderColor = "Tomato";

Thank you.

3 Replies

SG Shyam G Syncfusion Team May 24, 2018 08:14 AM UTC

Hi Gyorgy Gorog, 
 
We have created a MVC sample in which we have set an addInfo property for nodes and retrieved it in the client side(.cshtml file) using click event. Please refer to the code example and sample below. 
Also please look in to highlighted code below which shows how to get addInfo property in click event which is defined in MVC. 
 
Code example: 
 
DiagramController.cs 
 
  BasicShape node = new BasicShape(); 
   //create addInfo property for node 
   Dictionary<string, object> addInfo = new Dictionary<string, object>(); 
   addInfo.Add("email", "[email protected]"); 
   node.AddInfo = addInfo; 
   Diagram.Nodes.Add(node); 
 
 //define click event 
 Diagram.Click = "click"; 
 
  function click(args) { 
        if (args.element) { 
            if (args.element.addInfo) { 
                             //retrieve addInfo property 
                alert(args.element.addInfo.email); 
            } 
        } 
    } 
 
 
Please let us know if any concerns. 
 
Regards, 
Shyam G 



GG Gyorgy Gorog May 24, 2018 11:34 AM UTC

Shyam, quite logical, I just trusted the context menu that never lists addInfo: Thanks anyway.




SG Shyam G Syncfusion Team May 25, 2018 01:12 PM UTC

Hi Gyorgy Gorog, 
 
Could you please confirm us whether you need to get an node’s addInfo property before opening the context menu. If yes, please use contextMenuBeforeOpen event in which you get an node in args.target property. please refer to the code example and help documentation below. 
 
Code example: 
 
model.ContextMenuBeforeOpen = "contextMenuBeforeOpen"; 
 
        function contextMenuBeforeOpen(args) { 
            alert(args.target.addInfo.email) 
        }; 
 
 
Regards, 
Shyam G 


Loader.
Up arrow icon