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

Loop through Swimlane Children nodes in Javascript

Hello,
I have created a diagram with swimlanes and nodes inside that which has connectors as well. Please find the attached screenshot. I am trying to loop through the entire diagram and identify each node and set the fillColor as white. It works correctly for all nodes outside the swimlane but couldnt find the nodes inside the swimlane. I tried using isSwimlane true and getting the children nodes but didnt work. I pasted the javascript below. Can you advise?
var diagram = $("#Diagram1").ejDiagram("instance");
//var jsonData = JSON.parse(data);
//load the JSON data to diagram
for (inodes = 0; inodes < diagram.model.nodes.length; inodes++) {
var allnode = diagram.model.nodes[inodes];
diagram.updateNode(allnode.name, { fillColor: "white" });
//debugger;
if (diagram.model.nodes[inodes].isSwimlane == true) {
for (i = 0; i < diagram.model.nodes[inodes].children.length; i++)
{
var child = diagram.getNode(diagram.model.nodes[inodes].children[i]);
diagram.updateNode(child.name, { fillColor: "white" });
}
//debugger;
}
}

Attachment: SwimlaneDiagram_284d1ac9.zip

1 Reply

SG Shyam G Syncfusion Team September 28, 2017 12:32 PM UTC

Hi Karthick, 
 
The swimlane structure created at the initial rendering will be converted into the group node internally with its children as a string and added it into the model nodes collection. So please use getNode method to get the swimlane structure and then iterate the lanes to get the children in lane. Please refer to the code example below in which we have shown how to get the nodes from the lane. Also please refer to the playground link for more details.  
 
Code example: 
 
function getLaneChildren() { 
            var diagram = $("#diagram").ejDiagram("instance"); 
            for (var i = 0; i < diagram.model.nodes.length; i++) { 
                var node = diagram.model.nodes[i]; 
                if (node.isSwimlane) { 
                    //to get the swimlane structure 
                    var swimlane = diagram.getNode(node); 
                    //iterate the lanes 
                    for (var j = 0; j < swimlane.lanes.length; j++) { 
                        var lane = swimlane.lanes[j]; 
                        //iterate the children in lane 
                        for (k = 0; k < lane.children.length; k++) { 
                            //get the children in lane 
                            var child = lane.children[k]; 
                        } 
                    } 
                } 
            } 
        } 
 
 
Regards, 
Shyam G 
 


Loader.
Live Chat Icon For mobile
Up arrow icon