PDA

View Full Version : Method to set a tree node as leaf or non-leaf



mx_starter
5 Nov 2013, 3:27 AM
Hi guys, please look at the attached screenshot:

46703

As you can see - the node with text '2222' is a leaf node. The tree store is populated remotely.
Well - i have function which handles an event for this node and which creates a new node that is a child of '2222'.

Now i want the tree panel to be updated automatically so that '2222' to become from leaf to non-leaf and to be automatically expanded showing the newly created child and changing its icon respectively.

However, when i use the expand() method for that node OR when i call treeStore.load() (with node 2222 as a param) - nothing happens. This is probably because the node is already marked as leaf and therefore - not expandable. These two methods are OK with any of the other nodes in the tree.

So - how to solve this? Initially - i was looking for a method similar to node.setLeaf(true/false), but there is no such thing in the docs.

After several times playing around - i suddenly found that i can implement this using the data property of the node instance. So - setting the following:


node.data.leaf = false;
node.expand();

did for me exactly what i wanted with just 2 lines of code.

However, i'm afraid that this is bad ExtJS practice and therefore the question is:

Why not just create a method, named for example setLeaf(bool) which to be included in the framework?

Cheers :)

mx_starter
5 Nov 2013, 3:47 AM
Well - i have function which handles an event for this node and which creates a new node that is a child of '2222'.


Correction! The above text in red is obviously incorrect because the handler does NOT create a new node, but simply new entry into the server backend.

That's why the treeStore.load() method is needed to retrieve the new data from server (or just node.expand() if the node is still not expanded)

But i believe my question is still reasonable

Gary Schlosberg
7 Nov 2013, 9:55 AM
I don't see getters or setters for any of the other configs for Ext.data.NodeInterface (http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.NodeInterface). Perhaps a developer will shed some light, but perhaps the fact that it was so easy to accomplish otherwise plays into it.