How to uncheck all tree nodes in Ext.tree.TreePanel?

13,467

Solution 1

tree.getRootNode().cascade(function(n) {
    var ui = n.getUI();
    ui.toggleCheck(false);
});

As found here: http://www.sencha.com/forum/showthread.php?12888-solved-programatically-unchecking-checked-tree-nodes&p=62845#post62845

Solution 2

I found a method as below, but seems the 'casecade' method do not worked well, I need call 'reset' several times to unchecked all the checked children:

reset: function (){
            startNode = this.root;
            var f = function () {
                if (this.attributes.checked) {
                    this.attributes.checked = false;
                    this.getUI().toggleCheck(false);
                }
            };
            startNode.cascade(f);
        }

Solution 3

I was unable to get either of the other answers to work with Extjs 4.0.7. Also, the use of the "cascade" method issued a warning that it's deprecated. It recommended using "cascadeBy" instead. Other than the method name, I was unable to find a difference in the method signature (same arguments, this, behaviour).

However, I was able to find this code that worked:

{ 
    xtype: 'button', 
    text: 'Deselect All',
    listeners:{
        click: function(){

            var tree = Ext.ComponentQuery.query( 'treepanel[itemId=user_flags_tree]')[0];
            tree.getRootNode().cascadeBy(function(){

                this.set( 'checked', false );

            });

        }
    }
}

Thanks to this post: http://www.sencha.com/forum/showthread.php?149627-Programmaticaly-check-uncheck-checkboxes-in-the-Tree-panel

Share:
13,467
mothee
Author by

mothee

Updated on June 25, 2022

Comments

  • mothee
    mothee almost 2 years

    I would like a 'reset' method to uncheck all the checked nodes in Ext.tree.TreePanel.

  • martyglaubitz
    martyglaubitz almost 12 years
    truly, cascadeBy(function(){this.set( 'checked', false );}); does the trick!