PDA

View Full Version : [CLOSED] Force layout of Button's children



RCN
Oct 23, 2012, 2:57 PM
Hi folks, i would like to know whether it's possible to force the redering of button's menu. In the following example, the Menu's AfterRender event (line 12) is just fired when the button _btn is clicked.

To overcome this issue it's possible to call Menu's doAutoRender method (Please uncomment from line 16 to 18) after button's rendering, but i'm not sure that it's the best approach to accomplish my needs.

What you think about it?

Thanks in advance.



<ext:Toolbar ID="Toolbar1" runat="server" Width="500">
<Items>
<ext:Button ID="_btn" runat="server" Text="Click Me" Icon="Application">
<Menu>
<ext:Menu ID="_mnl" runat="server">
<Items>
<ext:MenuItem Text="Menu 1" Icon="Accept" runat="server" />
<ext:MenuItem Text="Menu 1" Icon="Accept" runat="server" />
<ext:MenuItem Text="Menu 1" Icon="Accept" runat="server" />
</Items>
<Listeners>
<AfterRender Handler="alert('Menu was rendered');" />
</Listeners>
</ext:Menu>
</Menu>
<%--<Listeners>
<AfterRender Handler="item.menu.doAutoRender();" />
</Listeners>--%>
</ext:Button>
</Items>
</ext:Toolbar>
</body>
</html>

Daniil
Oct 23, 2012, 7:28 PM
Hi Raphael,

I think your approach is good.

RCN
Oct 23, 2012, 8:38 PM
Button's showMenu (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.button.Button-method-showMenu) calls Menu's showBy (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.menu.Menu-method-showBy) method, that calls Abstract Component's doAutoRender (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.AbstractComponent-method-doAutoRender) method, that calls the Render method. When the button is pressed, it will call Menu's showBy (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.menu.Menu-method-showBy) again, but the Button's children will not be rendered again because Render method makes the following validation:



if (!me.rendered && me.fireEvent('beforerender', me) !== false)


so, the button's children are not rendered twice

The "stack trace" is a little confusing, but in my opnion there is no performance leak, so i think that it's an acceptable approach.

Daniil, if you agree, please mark this thread as closed.

Thank you.

Vladimir
Oct 23, 2012, 9:49 PM
Can you clarify why do you need it (force menu rendering )?
Do you need instance of menu? Or menu contains fields which must be submitted?

RCN
Oct 24, 2012, 11:47 AM
I have a GridPanel within Button's Menu. it must be populated when its rendering is complete. So i populate it when AfterRender event is fired but it's just fired when the button is clicked by the first time, otherwise the GridPanel does not exist.

geoffrey.mcgill
Oct 24, 2012, 1:36 PM
http://forums.ext.net/showthread.php?3440-Forum-Guidelines-For-Posting-New-Topics

#1 http://forums.ext.net/showthread.php?10205-More-Information-Required

Daniil
Oct 26, 2012, 5:53 PM
Hi Raphael,

Please clarify is the issue still actual?

RCN
Oct 26, 2012, 7:22 PM
i am gonna prepare an example. please wait until monday.

Daniil
Oct 29, 2012, 8:51 AM
Sure, no problem. Thanks.

NOTE

Marked closed. Please feel free to update the thread with a sample.