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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Expand node and childs

Thread ID:

Created:

Updated:

Platform:

Replies:

123697 Apr 12,2016 10:31 AM UTC Apr 13,2016 12:54 PM UTC ASP.NET MVC 2
loading
Tags: TreeView
Jaime
Asked On April 12, 2016 10:31 AM UTC

How can I expand/collapse the node AND his childs by javascript?
This is what i tried so far:

1º try
var treeviewObj = $("#treeInstalaciones").data("ejTreeView");
treeviewObj.collapseAll();
This only collpase the root of the treeview. But if the user open it again, the nodes inside root, has been no modified. They still open/close. Also I don'w tant to collpase/expand all the treeview. Only a specific node.

2º try:
var treeviewObj = $("#treeInstalaciones").data("ejTreeView");
treeviewObj.collapseNode(treeviewObj.getSelectedNode()[0]);
It collapse the node. However its child are not modified. Same problem before.

3º try:
function collapseNodeAndChild(itemNode) {
        debugger;
        var treeviewObj = $("#treeInstalaciones").data("ejTreeView");
        var nodesToCollapse = [];
        nodesToCollapse.push(itemNode);

        while (nodesToCollapse.length > 0) {
            var child = nodesToCollapse[0];
            nodesToCollapse.pop(child);
            treeviewObj.collapseNode(child); //When this instrucction its executed, it exit the function, and the next code its not executed.

            for (i = 0; i < child.childNodes.length; i++) {
                var childInner = child.childNodes[i];
                if (childInner.innerHTML.startsWith("<ul ")) {
                    for (j = 0; j < childInner.childNodes.length; j++) {
                        if (childInner.innerHTML.startsWith("<li ")) nodesToCollapse.push(childInner[j]);
                    }
                }
            }
        }
    }
Here i'm trying to collpase the node, check if it has childs, and collapse them. However when treeviewObj.collapseNode(child); is executed, the function ends, and the next code is never executed.



When i need is:
INITIAL STATE
  • GrandFahter
    • Father
      • Son
        • Car
        • Bike
      • Daugther
        • Bike

THE USER COLLAPSE THE NODE "FATHER" CLICKING A BUTTON  WHICH EXECUTE SOME JAVASCRIPT CODE
  • GrandFahter
    • Father
THE USER OPEN THE NODE FATHER CLICKIN ON THE TREEVIEW
  • GrandFahter
    • Father
      • Son
      • Daugther
As you can see, "Son" and "Daugher" are collapse, due the user had collpased Father node.


Jaime
Replied On April 12, 2016 12:37 PM UTC

4º Try (After Update to version 14.1451.0.41)
function collapseNodeAndChild(itemNode) {
        debugger;
        var treeviewObj = $("#treeInstalaciones").data("ejTreeView");
        var nodesToCollapse = [];
        nodesToCollapse.push(itemNode);

        for (i = 0; i < nodesToCollapse.length; i++) {
            var child = nodesToCollapse[i];

            for (j = 0; j < child.childNodes.length; j++) {
                var childInner = child.childNodes[j];
                if (childInner.innerHTML.indexOf("<ul ") >= 0) {
                    for (k = 0; k < childInner.childNodes.length; k++) {
                        var childLI = childInner.childNodes[k];
                        nodesToCollapse.push(childLI);
                    }
                }
            }
        }

        var nodesReverse = nodesToCollapse.reverse();

        while (nodesReverse.length > 0) {
            var child = nodesReverse[0];
            nodesReverse.splice(0, 1);

            treeviewObj.collapseNode(child);
        }
    }

Whith this code only the last child is collapsed. BUT, if execute in the chrome console nodesReverse.splice(0, 1); before entering the while, the second child is collapsed!!

It seems like a bug. I have checked that, If execute in the console the instruction nodesReverse.splice(0, 1);  X times before entering the while, I can collapse every child with no problem. However it seems that it only allow to collapse 1 node.

Piramanayagam Ramakrishnan [Syncfusion]
Replied On April 13, 2016 12:54 PM UTC

Hi Jaime,


We have checked with your query and created a new incident under your account to track the status of the issue reported in this forum. Please log on to our support website to check for further updates.


https://www.syncfusion.com/account/login?ReturnUrl=%2fsupport%2fdirecttrac%2fincidents


Regards,

Piramanayagam R


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;