views:

3214

answers:

2

How can I change the attributes of a tree node?

One tree node has the following attributes:

{"id":"75",
"description":"My Tree Node",
"status":"25"
"uiProvider":"col",
"leaf":true}

Now my script receives the following data

{
"id":"75",
"status":"100",
"cls":"done"
}

I try to update the attributes (UPDATED):

// a.result.data has the new data and taskID is the node's id
for (var property in a.result.data)
{ 
  tree.getNodeById(taskID).attributes[property] = a.result.data[property];
}

The tree, however, does not get updated.

How can I make the tree show the changes? I need the node to change existing attributes and add the new attributes.

I appreciate your help!

A: 

From the extjs forums:

function refreshNodeColumns(n)
{
    var t = n.getOwnerTree();
    var a = n.attributes;
    var cols = t.columns;
    var el = n.ui.getEl().firstChild; // <div class="x-tree-el">
    var cells = el.childNodes;

    //<div class="x-tree-col"><div class="x-tree-col-text">

    for(var i = 1, len = cols.length; i < len; i++)
    {
        var d = cols[i].dataIndex;
        var v = (a[d]!=null)? a[d] : '';
        if (cols[i].renderer) v = cols[i].renderer(v);
        cells[i].firstChild.innerHTML = v;        
    }
}

Should work if you call it after your update loop.

timdev
Thanks but I tried it and it doesn't do anything. Firebug says not js errors.
Alex L
I got this to work. The function updated all the columns except for the Text column. For that I had to use node.setText(a.result.data.description)
Alex L
A: 

Hi,

I am on similar issue but little different!

First I am rendering the tree and I want to reload the same tree with more/less children/leaves dynamically.

I have tried by setting dataUrl param, but it is not getting loaded.

Do you have an idea, how can I solve this problem?

Thanks, Sri

Sri
You should ask it as new question. Look herehttp://www.extjs.com/deploy/ext/docs/output/Ext.tree.TreeLoader.htmlAdd a condition using beforeload event and use root.tree.reload
Alex L