checkboxtreedojodijit.tree

dojo/dijit tree checkbox select child when parent clicked


I found the working example online and I can see check box adjacent to each node of the tree The fiddle link mentioned last section given below:

Dojo tree with checkbox not displaying

Now my requirement is when the parent node is checked, all the child node should also gets checked and it should work in DOJO 1.3 release Can help someone help fix the fiddle code


Solution

  • Within the checkbox listener you can put code to find the children and check them also: The tree has to bexpanded before adding the other checkmarks because the children nodes are not created till the parent is expanded the first time.

        dojo.connect(cb, "onChange", function() {
        var treeNode = dijit.getEnclosingWidget(this.domNode.parentNode);
        //treeNode.expand();
        treeNode.tree._expandNode(treeNode);
        dojo.publish("/checkbox/clicked", [{
          "checkbox": this,
          "item": treeNode
        }]);
    
        var parentcb = this;
        console.log(parentcb.checked)
          treeNode.getChildren().forEach(function(item) {
          var checkbox =  dijit.getEnclosingWidget(item.labelNode.children[0]);
         checkbox.set('checked', parentcb.checked)
      });
      });
    

    Fiddle:http://jsfiddle.net/mcfskLop/8/