PDA

View Full Version : TreePanel: BeforeExpand event on element that has no child



neolitec
15 Nov 2011, 2:17 AM
Hello,

I have a TreePanel with some static elements and other elements that must be dynamically loaded.
So I want to detect the BeforeExpand event on each parent in order to load their children.
When I try to expand the element, BeforeExpand is not fired and the expand pics disappears (like the folder icon).

Why? :-/

At the moment, the OnClick event is detected to load the children. And I noticed that after the OnClick, BeforeExpand can be fired.
I understand now that BeforeExpand can not be fired if the element that trigger it has no child. Why it works that way? >:)

This does not suit me at all! Is there another solution?

Thx

micgala
16 Nov 2011, 2:23 AM
Hi.

In your tree class, you can try to override the hasChildren method.
That method will return true if the parent has children.

If you want it to return true by any other means, override it and add what you need.

Hope that helps you.

Regards,
Michel.

neolitec
16 Nov 2011, 2:39 AM
Hi micgala,

Thank for your answer, indeed, i've already override hasChildren method and it works nice :
I have an element with a folder icon, but without children (they have been detected as parent element by my hasChildren overriden method).
So I can expand it (I see the expand icon).

When I try to expand it, I noticed that BeforeExpand is not fired (I need it to load the children).
And just after, my element is repainted and seems not to be detected as a parent (folder and expand icon disappear).

That's why I said "I understand now that BeforeExpand can not be fired if the element that trigger it has no child".

hulseware
16 Feb 2012, 4:51 AM
I had a similar problem - you don't get the expander on the tree node without a child. So on those nodes that I know need future expansion, I add a child node with the name field of Expanding... and have a hidden attribute in the tree store that indicates if the query has occurred yet (which is set on the node that needs expanding, not on the Expanding... node). Now I have an expander icon on the node in the tree. When I click the expander, the tree visually expands, showing the Expanding... node, then the BeforeExpand is fired. I look at the node queried field. If it is not set to true, I do the server query and mask the tree to prevent other operations. When the storeDataChanged method runs later, I remove the Expanding... child, replace it with the query results, and then unmask the tree.

neolitec
16 Feb 2012, 5:05 AM
Yes, I finally solved the problem excatly the same way.
But in my opinion there must/should be a better method to do it... Only the loading icon should be visible.