Git Product home page Git Product logo

Comments (7)

rfalke avatar rfalke commented on August 15, 2024

I'm also interested in a solution to this problem. I want a toggle behavior: click will select the node and clicking again unselects it.

from angular-tree-control.

ferryfax avatar ferryfax commented on August 15, 2024

I need to do this as well. How the heck do you clear a selected node?

from angular-tree-control.

kadarbasha avatar kadarbasha commented on August 15, 2024

I guess you need to change the following function in angular-tree-control.js in order to work for unselection condition.

$scope.selectNodeLabel = function( selectedNode ){
                        if (selectedNode[$scope.options.nodeChildren] && selectedNode[$scope.options.nodeChildren].length > 0 &&
                            !$scope.options.dirSelectable) {
                            this.selectNodeHead();
                        }
                        else {
                            if ($scope.selectedNode != selectedNode) {
                                $scope.selectedNode = selectedNode;
                                if ($scope.onSelection)
                                    $scope.onSelection({node: $scope.selectedNode});
                            }
                        // resetting the already selected node
                          else{
//selected-node="selectedNode" attribute is binded to
//$scope.selectedNode scope attribute in the directive so it needs to be clear in order to work.
                               $scope.selectedNode = {};
                               if($scope.onSelection)
            $scope.Onselection({node: $scope.selectedNode});
                         } 
                        }
                    };

from angular-tree-control.

ferryfax avatar ferryfax commented on August 15, 2024

Actually, what I want to do is unselect the currently selected node from within my controller. Any suggestions on how I could achieve that?

from angular-tree-control.

ferryfax avatar ferryfax commented on August 15, 2024

Further to this. I've tried setting selected-node to an empty object but it doesn't re-draw the tree and the node is still highlighted.

from angular-tree-control.

kadarbasha avatar kadarbasha commented on August 15, 2024

check the plunkr example for unselecting the selected node.

http://plnkr.co/edit/CdKRwx?p=preview

In my previous comment I typed the function name wrongly because of that it doesn't work now. I have corrected it. check the example. I have written few lines in angular-tree-control.js file as

 $scope.selectNodeLabel = function( selectedNode ){
                        if (selectedNode[$scope.options.nodeChildren] && selectedNode[$scope.options.nodeChildren].length > 0 &&
                            !$scope.options.dirSelectable) {
                            this.selectNodeHead();
                        }
                        else {
                            if ($scope.selectedNode != selectedNode) {
                                $scope.selectedNode = selectedNode;
                                if ($scope.onSelection)
                                    $scope.onSelection({node: selectedNode});
                            }
                            // resetting the already selected node
                            else{
                          //selected-node="selectedNode" attribute is binded to
                          //$scope.selectedNode scope attribute in the directive so it needs to be clear in order to work.
                            $scope.selectedNode = { "label" : "", "id" : "", "children": [] };
                            if($scope.onSelection)
                            $scope.onSelection({node: $scope.selectedNode});
                            }
                        }
                    };

from angular-tree-control.

yoavaa avatar yoavaa commented on August 15, 2024

Added a fix to the component based on @kadarbasha suggestion. A second click on a selected node will now unselect it.

from angular-tree-control.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.