1. #1
    Ext User
    Join Date
    Jun 2007
    Posts
    14
    Vote Rating
    0
    dgersh is on a distinguished road

      0  

    Default [solved] programatically unchecking checked tree nodes

    [solved] programatically unchecking checked tree nodes


    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:
    Code:
    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

  2. #2
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,544
    Vote Rating
    64
    Animal is a jewel in the rough Animal is a jewel in the rough Animal is a jewel in the rough

      0  

    Default


    Code:
        myTree.getRootNode().cascade(function(n) {
            var ui = n.getUI();
            ui.toggleCheck(true);
        });
    The default TreeNodeUI needs documenting.

  3. #3
    Ext User
    Join Date
    Jun 2007
    Posts
    14
    Vote Rating
    0
    dgersh is on a distinguished road

      0  

    Default


    Perfect, thanks!

    Here's a snippet free for anyone to use

    Code:
    /**
     * 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:

    Code:
    /**
     * 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

    Code:
    //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);
    	  });	
    	}
    }

  4. #4
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,544
    Vote Rating
    64
    Animal is a jewel in the rough Animal is a jewel in the rough Animal is a jewel in the rough

      0  

    Default


    I've added docs for TreeNodeUI to SVN, and they'll show up in the next release.

  5. #5
    Ext User
    Join Date
    Aug 2007
    Posts
    15
    Vote Rating
    0
    jsxiaoqiang is on a distinguished road

      0  

    Default


    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.

  6. #6
    Sencha User
    Join Date
    Aug 2011
    Posts
    7
    Vote Rating
    0
    zhonghuafy is on a distinguished road

      0  

    Default


    Ext.getCmp('selconWPanel').getRootNode().cascade(function(n){
    var ui = n.getUI();
    ui.toggleCheck(false);
    });
    this does not work. IE says: "对象不支持此属性或方法".