1. #1
    Sencha Premium Member
    Join Date
    Dec 2007
    Posts
    38
    Vote Rating
    2
    babsjr77 is on a distinguished road

      0  

    Default Fast tree expandAll/collapseAll

    Fast tree expandAll/collapseAll


    I needed a faster way in ExtJS 4.1 to expand and collapse all the nodes in a large tree. The following method is much faster than calling tree.expandAll() and tree.collapseAll(). Be aware this will not fire expand or collapse events.

    Code:
    updateTreeView : function(tree, fn) {
        var view = tree.getView();
        view.getStore().loadRecords(fn(tree.getRootNode()));
        view.refresh();
    },
    
    collapseAll : function(tree) {
        this.updateTreeView(tree, function(root) {
            root.cascadeBy(function(node) {
                if (!node.isRoot() || tree.rootVisible) {
                    node.data.expanded = false;
                }
            });
            return tree.rootVisible ? [root] : root.childNodes;
        });
    },
    
    expandAll : function(tree) {
        this.updateTreeView(tree, function(root) {
            var nodes = [];
            root.cascadeBy(function(node) {
                if (!node.isRoot() || tree.rootVisible) {
                    node.data.expanded = true;
                    nodes.push(node);
                }
            });
            return nodes;
        });
    }

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,532
    Vote Rating
    871
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Thanks for sharing your code!
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User mlgates's Avatar
    Join Date
    Sep 2014
    Location
    Missouri
    Posts
    1
    Vote Rating
    0
    mlgates is on a distinguished road

      0  

    Default


    Thanks for sharing this! It was a huge help!

Thread Participants: 2