Hybrid View

  1. #1
    Ext User
    Join Date
    Sep 2007
    Posts
    3
    Vote Rating
    0
    roger.bowman is on a distinguished road

      0  

    Default Stateful TreePanel

    Stateful TreePanel


    Hello all!

    Since I couldn't find a way to make a TreePanel remember it's state (i.e. remember which nodes were expanded/collapsed), I figured I would post my solution here.

    All I had to do was add the following to my TreePanel configuration:

    Code:
        stateEvents : ['collapsenode', 'expandnode'],
        stateId : 'tree-panel-state-id',
        stateful : true,
        getState : function () {
            var nodes = [];
            this.getRootNode().eachChild(function (child) {
                //function to store state of tree recursively
                var storeTreeState = function (node, expandedNodes) {
                    if(node.isExpanded() && node.childNodes.length > 0) {
                        expandedNodes.push(node.getPath());
                        node.eachChild(function (child) {
                            storeTreeState(child, expandedNodes);
                        });
                    }
                };
                storeTreeState(child, nodes);
            });
                
            return {
                expandedNodes : nodes
            }
        },
        applyState : function (state) {
            var that = this;
            this.getLoader().on('load', function () {
                var nodes = state.expandedNodes;
                for(var i = 0; i < nodes.length; i++) {
                    if(typeof nodes[i] != 'undefined') {
                        that.expandPath(nodes[i]);
                    }
                }
            });
        }
    Any comments/suggestions are more than welcome!

    Cheers,
    -Roger

  2. #2
    Ext User
    Join Date
    Sep 2007
    Posts
    3
    Vote Rating
    0
    roger.bowman is on a distinguished road

      0  

    Default


    To keep state while refreshing the tree, I added a refresh button to the tree panel tool bar:

    Code:
        id : 'refresh',
        qtip : 'Refresh',
        handler : function (event, toolEl, panel) {
            var thisTreePanel = panel.getComponent('tree-panel');
    						
    	//get state from tree
    	var state = thisTreePanel.getState();
    	panel.body.mask('Loading', 'x-mask-loading');
    
            thisTreePanel.getLoader().load(thisTreePanel.getRootNode(), function () {
    	    panel.body.unmask();
                thisTreePanel.applyState(state);							
    	});
        }
    However, I was having issues where if I collapsed a node, it would not remember that the node was collapsed when I refreshed the tree. If I reloaded the entire page, however, it would remember that the node was collapsed. With that in mind, I changed the applyState method above to the following:

    Code:
    applyState : function (state) {
        var that = this;
        this.getLoader().on('load', function () {
            //read state in from cookie, not from what is passed in
            var cookie = Ext.state.Manager.get('content-manager-tree-panel');
            var nodes = cookie.expandedNodes;
            for(var i = 0; i < nodes.length; i++) {
                if(typeof nodes[i] != 'undefined') {
                    that.expandPath(nodes[i]);
                }
            }
        });
    }
    Hope this helps someone. Please let me know what you think/anything I could do better/any bugs you find.

    Thanks,
    -Roger

  3. #3
    Sencha User
    Join Date
    Apr 2007
    Posts
    90
    Vote Rating
    0
    marcing is on a distinguished road

      0  

    Default


    Just what I needed! Thank You so much!

  4. #4
    Sencha User galdaka's Avatar
    Join Date
    Mar 2007
    Location
    Spain
    Posts
    1,166
    Vote Rating
    -1
    galdaka is an unknown quantity at this point

      0  

    Default


    Quote Originally Posted by marcing View Post
    Just what I needed! Thank You so much!
    You can view my plugin: http://www.extjs.com/forum/showthrea...943#post212943

    Greetings,

  5. #5
    Sencha Premium Member
    Join Date
    Jun 2008
    Posts
    322
    Vote Rating
    4
    Scorpie is on a distinguished road

      0  

    Default


    This looks like something I need for my problem described here: http://www.extjs.com/forum/showthread.php?t=46252

    Does this also work with getting & selecting the previous selected Node?
    I`m from Holland!

  6. #6
    Ext User
    Join Date
    Sep 2007
    Posts
    3
    Vote Rating
    0
    roger.bowman is on a distinguished road

      0  

    Default


    Quote Originally Posted by Scorpie View Post
    This looks like something I need for my problem described here: http://www.extjs.com/forum/showthread.php?t=46252

    Does this also work with getting & selecting the previous selected Node?
    AFAIK, it does not. It only "remembers" which nodes were expanded/collapsed.

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi