Results 1 to 7 of 7

Thread: Reloading Tree

  1. #1

    Default Reloading Tree

    Say I have TreePanel with bunch of nodes expanded. I need to reload that tree but keep all expanded nodes as they are. If I call tree.getLoader().load(tree.root) it reloads only nodes below the root. So far Im clear why: I don't pass to my server any info about expanded nodes.

    Question: is there way to setup the Tree to pass info to the server about expanded nodes during its load?

    I can do it myself by expanding class, traversing nodes, building string with all expanded nodes hierarchy and passing it as parameter to the load URL but... Before inventing the wheel I was hoping someone already done it.

  2. #2
    Sencha Premium User
    Join Date
    Oct 2007
    Location
    Berlin, Germany
    Posts
    891

    Default

    Quote Originally Posted by aresot View Post
    Question: is there way to setup the Tree to pass info to the server about expanded nodes during its load?
    this should be handled by the server side code which generates the children. You can submit a custom param like

    PHP Code:
    baseParams: {
        
    expandAllMyNodes:true;

    but your server code need to react on this and return all nodes with the config

    PHP Code:
    expanded:true 
    This way the treeloader gets agaiun triggered on theses nodes thus your whole tree will get expanded again.
    if you now only want specific nodes to be expanded you can also handle this by the same method. E.g.
    PHP Code:
    baseParams: {
        
    expandOnlyTheseIds:[0,5,6,10,43];

    But, again, your server code which generates the child must compare these given values before sending back to the server.

    In short: It's not Ext's Job to return the wanted childs, the serverside code has to do it.

  3. #3

    Default

    I think I didn't explain it well:
    I do realize that it is server that builds JSON for all expanded nodes but my question was if there was already function that generates expandOnlyTheseIds list from your example and if there is already existing function or config that passes that into HTTP request.

    I certainly can write function that traverses all tree nodes and joins all expanded ones into request string. Was wondering if that is already build in Tree or someone might have done it already.

    I don't like the idea of marking nodes as 'expanded' in JSON since it will generate server request for every expanded node and I prefer to do it in single trip to server.

  4. #4
    Sencha Premium User
    Join Date
    Oct 2007
    Location
    Berlin, Germany
    Posts
    891

    Default

    Quote Originally Posted by aresot View Post
    I think I didn't explain it well:
    I do realize that it is server that builds JSON for all expanded nodes but my question was if there was already function that generates expandOnlyTheseIds list from your example and if there is already existing function or config that passes that into HTTP request.

    I certainly can write function that traverses all tree nodes and joins all expanded ones into request string. Was wondering if that is already build in Tree or someone might have done it already.

    I don't like the idea of marking nodes as 'expanded' in JSON since it will generate server request for every expanded node and I prefer to do it in single trip to server.
    So you are asking for serverside examplecode? (Because you already know you could pass a custom param to the treeloader) Well, that totally depends on how the json is accessed and what serverside language you are using (PHP,JSP,ASP..?). I retrieve all data from an oracle database and its tree-logic is spread over several tables. Not anything i could share here and nothing that would help you out. Maybe someone else has a simple example.

  5. #5

    Default

    Not server side. Question is about client side Tree. Is there anything in TreePanel or TreeStore that already has this functionality.

  6. #6

    Default

    Anyhow, here is couple overwrites to build expanded nodes string and reload tree:
    Code:
    Ext.tree.TreePanel.prototype.reload = function () {
        // traverse expanded nodes and update baseParams object
        var loader = this.getLoader();
        loader.baseParams.expanded=this.root.getExpandedString();
        loader.load(this.root);
    }
    Ext.tree.TreeNode.prototype.getExpandedString = function () {
        var tmp="",node;
        for (var i=0; i<this.childNodes.length; i++) {
            node=this.childNodes[i];
            if (node.isExpanded() && !node.isLeaf()) {
                if (tmp.length>0)    tmp+=",";
                tmp+=node.getExpandedString();
            }
        }
        if (tmp.length>0)   return [this.id,":{",tmp,"}"].join('');
        return this.id;
    }
    This will add "expanded" parameter to the server's request.

  7. #7
    Sencha Premium User
    Join Date
    Oct 2007
    Location
    Berlin, Germany
    Posts
    891

    Default

    Quote Originally Posted by aresot View Post
    Anyhow, here is couple overwrites to build expanded nodes string and reload tree:
    This will add "expanded" parameter to the server's request.
    Cool thing. Thanks for sharing and sorry for misunderstanding your question at first...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •