Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check child nodes of a tree when a parent is clicked [ExtJS]

Tags:

tree

extjs

extjs3

I would like to know how can i check the sibling nodes of a tree while clicking on a particular node in ExtJs.

I had given id's for each node and i can access the id of a clicked node. then how can i proceed to checking the child nodes automatically ??

somebody please help me..

like image 565
tismon Avatar asked Feb 16 '10 07:02

tismon


2 Answers

// or any other way of getting hands on the node you want to work with
var node = treePanel.getNodeById('your-id');
node.eachChild(function(n) {
    n.getUI().toggleCheck(true);
});

If you want this to work on the whole subtree of the current node, you'll have to do some recursion.

A little more integrated:

treePanel.on('checkchange', function(node, checked) {
    node.eachChild(function(n) {
        n.getUI().toggleCheck(checked);
    });
});
like image 119
Stefan Gehrig Avatar answered Sep 28 '22 06:09

Stefan Gehrig


function nodeCheck(node) {
    node.eachChild(function(n) {
        if(n.hasChildNodes())
            nodeCheck(n)
        n.getUI().toggleCheck(false);
    });
}
var node = (tree.getSelectionModel().getSelectedNode()) ? tree.getSelectionModel().getSelectedNode() : tree.root;
if(node) nodeCheck(node);

It works well for me ;)

like image 37
slammer Avatar answered Sep 28 '22 04:09

slammer