PDA

View Full Version : setText() and sorting in Tree



lightaiton
11 Oct 2007, 11:40 PM
Hi,

First of all, sorry for such a basic question.

I am using Ext(v1.1.1) for the first time to build a tree.

Basically, I need the tree to be sorted after editing text on a node.

TreeSorter is set to use the text as sorting criteria and it automatically sorts itself
when a node is added using appendChild()

However, when I edit the text on a node using node.setText(), text on the node get updated but the tree doesn't get sorted.


// create TreePanel
var tree = new Ext.tree.TreePanel('MyTree', {rootVisible: true});
.....

// create TreeSorter with default text as sorting criteria
new Ext.tree.TreeSorter(tree, {folderSort:false});
.....

// append children: gets sorted as soon as new node is added
tree.root.appendChild(newNode);
....

// set text on a node: text is changed but the tree doesn't get sorted
var oldNode = tree.getNodeById(newNode.id);
oldNode.setText("edited");

Can anyone help me ?

Do I need to refresh the tree manually and if so, how do I do that ?

Thanks.

fay
12 Oct 2007, 1:23 AM
Sorry I don't have much experience with trees, but from a quick look at ext-all-debug.js, TreeSorter has two methods that might work: doSort(node) and updateSort(tree, node).

para
12 Oct 2007, 5:25 AM
I actually added a function to TreeNode. This seems to work great for me.
This probably isn't the best way to handle it, but it does work well.


Ext.override(Ext.tree.TreeNode, {
rename: function(text) {
this.setText(text);
if(this.getOwnerTree()) {
this.getOwnerTree().fireEvent('beforechildrenrendered', this.parentNode);
}

}

});

lightaiton
15 Oct 2007, 3:21 PM
I actually added a function to TreeNode. This seems to work great for me.
This probably isn't the best way to handle it, but it does work well.


Ext.override(Ext.tree.TreeNode, {
rename: function(text) {
this.setText(text);
if(this.getOwnerTree()) {
this.getOwnerTree().fireEvent('beforechildrenrendered', this.parentNode);
}

}

});


Thanks guys.

This code worked fine.



node.setText('newText');
node.fireEvent('beforechildrenrendered', node.parentNode);