3

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

jonsca
  • 10,218
  • 26
  • 54
  • 62
mothee
  • 141
  • 2
  • 4
  • 12

4 Answers4

7
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

Mischa Kroon
  • 1,772
  • 1
  • 13
  • 19
2

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

Homer6
  • 15,034
  • 11
  • 61
  • 81
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);
        }
mothee
  • 141
  • 2
  • 4
  • 12
0
var nodes = treePanel.getView().getNodes();
var records = treePanel.getView().getRecords(nodes);
for (var i = 0; i < records.length; i++) {
    records[i].set('checked',true);
}
Dharmesh Hadiyal
  • 719
  • 1
  • 7
  • 18