angular-tree-control icon indicating copy to clipboard operation
angular-tree-control copied to clipboard

Auto expand to selected-node

Open ronnyek opened this issue 9 years ago • 2 comments

I've got a grid that I effectively find a node and set it to selected, and that works, but because I dont know the path to that node I dont necessarily have all the treenodes above it expanded.

Either api functions like findnode, or get path to selected node would help me expand automatically.. or just a setting to say expand selected nodes would be huge

ronnyek avatar Jan 31 '16 18:01 ronnyek

Would be nice +1

sebastienvermeille avatar Feb 22 '16 15:02 sebastienvermeille

Please try to use this library. https://github.com/dabeng/JSON-Loop

Because I have asked this question 1 year back and tree-control is not able to solve the problem. So I have given my data to the JSON-Loop library to find the parent nodes. If you want the code to find parent node to create path, I have written the following code. If you want you may use this code.

You can remove this code. if (angular.equals(parentNode.Type, "Module")) in the below function. This I have written specific for my project.

function findParentNodes(obj, id, nodes) {

    if (nodes == undefined) {
        nodes = [];
    }

    var jsonloop = new JSONLoop(obj, 'Id', 'Children');

    jsonloop.findNodeById(obj, id, function (err, node) {

        if (err) {
            console.log(err);
            return nodes;
        } else {
            nodes.push(node);
            console.log(nodes);
            jsonloop.findParent(obj, node, function (err, parentNode) {
                if (err) {
                    console.log(err);
                    return nodes;
                }

                if (angular.equals(parentNode.Type, "Module"))
                {
                    nodes.push(parentNode);
                }
                else {
                    console.log("id:" + node.Id + " parentid:" +

parentNode.Id); if (parentNode != 'undefined') { findParentNodes(obj, parentNode.Id, nodes); } else { return nodes; } }

            });
        }
    });
}

On Mon, Feb 22, 2016 at 9:15 PM, Sebastien Vermeille < [email protected]> wrote:

Would be nice +1

— Reply to this email directly or view it on GitHub https://github.com/wix/angular-tree-control/issues/186#issuecomment-187237684 .

muralinit avatar Feb 24 '16 05:02 muralinit