View Full Version : TreePanel: BeforeExpand event on element that has no child
15 Nov 2011, 2:17 AM
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?
16 Nov 2011, 2:23 AM
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.
16 Nov 2011, 2:39 AM
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".
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.
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.
Powered by vBulletin® Version 4.1.5 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.