PDA

View Full Version : [solved] programatically unchecking checked tree nodes



dgersh
13 Sep 2007, 4:17 AM
Hi-

Ext 1.1.1
AsyncTreeNodes

I've pored through the documentation and searched the forums with no luck. I'm trying to loop through all of the checked nodes in my tree and uncheck them, but I can't find a function and setting the property doesn't change their appearance in the UI.

Here's why I've been trying:


function clearChecks()
{
var a_checked_nodes = page_tree.getChecked("id");
for (var i = 0; i < a_checked_nodes.length; i++)
{
page_tree.getNodeById(a_checked_nodes[i]).attributes.checked = false;

}
}


Anyone get something like this to work?

Thanks,

-David

Animal
13 Sep 2007, 4:58 AM
myTree.getRootNode().cascade(function(n) {
var ui = n.getUI();
ui.toggleCheck(true);
});


The default TreeNodeUI needs documenting.

dgersh
13 Sep 2007, 5:48 AM
Perfect, thanks!

Here's a snippet free for anyone to use



/**
* Toggle check boxes on a tree
* @param TreePanel o_tree
* @param bool b_checkState true to check all, false to uncheck all
*/
function toggleChecks(o_tree, b_checkState)
{
o_tree.getRootNode().cascade(function(n) {
var ui = n.getUI();
ui.toggleCheck(b_checkState);
});
}


other modifications you might want to use could be:



/**
* Pseudocode not tested...
* Toggle check boxes on a tree
* @param TreePanel o_tree
* @param string s_node_id Node id to run function on
* @param bool b_checkState true to check all, false to uncheck all
*/
function toggleChecks(o_tree, i_node_id, b_checkState)
{
o_tree.getNodeById(i_node_id).cascade(function(n) {
var ui = n.getUI();
ui.toggleCheck(b_checkState);
});
}


or even



//pseudocode
function toggleChecks(o_node, s_dir, b_checkState)
{
if (s_dir == 'up')
{
o_node.bubble(function(n) {
var ui = n.getUI();
ui.toggleCheck(b_checkState);
});
}
else
{
o_node.cascade(function(n) {
var ui = n.getUI();
ui.toggleCheck(b_checkState);
});
}
}

Animal
13 Sep 2007, 5:53 AM
I've added docs for TreeNodeUI to SVN, and they'll show up in the next release.

jsxiaoqiang
27 Sep 2007, 9:06 AM
but when you call tree.getChecked() ,you still get the node which is checked last time,and seems not checked now.
ok,i see .you also need to change the node attribute.