ExtJS Tips: How to check/unceck all the nodes of a tree(Ext.tree.TreePanel)

This post will help you to achieve following:

  1. Checking/Unchecking all the nodes of a tree.
  2. Checking/Unchecking all the childnodes of a node.
  3. Checking/Unchecking all the siblings of a node.(see comments..)

If you want to check/uncheck all the node of a tree or all the child node of a parent node then following is the way to acheive it:

//function to check/uncheck all the child node.
function toggleCheck(node,isCheck)
 var args=[isCheck];
//this will also affect the passed parentNode(node).

Now calling this function for checking/unchecking all the node of a tree:

<br />
var tree=//ext js tree.<br />
toggleCheck(tree.root,true);//for checking all the nodes<br />
//or<br />
toggleCheck(tree.root,false);//for unchecking all the nodes<br />

Now calling above function for checking/unchecking all the children of a node:

<br />
var parentNode=//a node from tree.<br />
toggleCheck(parentNode,true);//for checking all the child nodes<br />
//or<br />
toggleCheck(parentNode,false);//for unchecking all the child nodes<br />

If you find any error or face any difficulty please let me know by comments.

Published in: on January 18, 2010 at 11:22 am  Comments (18)  
Tags: , ,