Unanswered: TreePanel: BeforeExpand event on element that has no child
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).
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?
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".
Add a Dummy Child to the tree node that needs future expansion
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.