PDA

View Full Version : [CLOSED] MenuPanel dymanic items are not selected



ermanni.info
Apr 28, 2013, 6:10 PM
Hi!

I'm using MenuPanel creating items dynamically. The items are created properly and normally respond to the Click event. The problem is that the clicked item does not get selected in MenuPanel. When items are defined via markup selection functions normally as an example:
http://examples2.ext.net/default.aspx#/Toolbar/Menu/MenuPanel/

What setting should be done to enable this feature?

Below is an example of the application. In my application I have several tabs and when one of them is activated perform dynamic loading MenuPanel.



<%@ Page Language="C#" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
}

[DirectMethod]
public void UpdateMenu()
{
MenuPanel1.Menu.Items.Clear();
var aux = new Random();
var max = aux.Next(1, 15);
for (int i = 0; i < max; i++)
{
MenuPanel1.Menu.Items.Add(new Ext.Net.MenuItem
{
ID = "menuItem" + i.ToString(),
Text = "Dynamic item " + i.ToString()
});
}
MenuPanel1.Menu.ReRender();
MenuPanel1.SetSelectedIndex(0);
}
</script>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script>
var menuItemClick = function (menu, item) {
App.PnlCenter.body.update(Ext.String.format("Clicked: {0}", item.text)).highlight();
};
</script>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:Window ID="Window1"
runat="server"
Title="MenuPanel"
Closable="false"
Width="600"
Height="370"
Layout="BorderLayout">
<Items>
<ext:TabPanel runat="server"
ID="tabManutencao"
Region="Center"
Border="False">
<Items>
<ext:Panel ID="TabPanel1"
runat="server"
Title="Tab1"
Layout="BorderLayout"
Border="false"
BodyPadding="0"
Flex="1">
<Items>
<ext:TextField ID="txtSample"
FieldLabel="Informe um valor:"></ext:TextField>
</Items>
</ext:Panel>
<ext:Panel ID="TabPanel2"
runat="server"
Title="Tab2"
Layout="BorderLayout"
Border="false"
BodyPadding="0"
Flex="1">
<Listeners>
<Activate Handler="#{DirectMethods}.UpdateMenu();"></Activate>
</Listeners>
<Items>
<ext:Panel ID="Panel1"
runat="server"
Width="350"
Layout="Accordion"
Split="true"
Region="West"
Margins="5 0 5 5"
Border="false">
<Items>
<ext:MenuPanel ID="MenuPanel1"
runat="server"
Title="MenuPanel with Selection Saving"
Icon="ArrowSwitch">
<Menu ID="Menu1" runat="server">
<Items>
</Items>
<Listeners>
<Click Fn="menuItemClick" />
</Listeners>
</Menu>
</ext:MenuPanel>
</Items>
</ext:Panel>
<ext:Panel
ID="PnlCenter"
runat="server"
Title="Selected Item"
BodyPadding="5"
Region="Center"
Margins="5 5 5 0"
/>
</Items>
</ext:Panel>
</Items>
</ext:TabPanel>
</Items>
</ext:Window>
</form>
</body>
</html>


Thanks!

Ermanni.

Daniil
Apr 29, 2013, 6:59 AM
Hi Ermani,

You should re-render the MenuPanel itself. Re-rendering its menu is not enough.

So, please replace

MenuPanel1.Menu.ReRender();
MenuPanel1.SetSelectedIndex(0);
with

MenuPanel1.SelectedIndex = 0;
MenuPanel1.Render();

ermanni.info
May 01, 2013, 2:49 PM
Hi!

Realized the changes suggested and the problem was solved!

Thanks!

Ermanni

Daniil
May 01, 2013, 2:53 PM
I retested, it works for me.

How does your test case look now?

ermanni.info
May 01, 2013, 5:47 PM
Daniil,

In the Click event MenuPanel'm running through a routine DirectMethod. In this routine consumption MenuPanel.SelectedIndex and am noticing a delay in updating this information. When I click the first item the SelectedIndex remains 0. When I click on item 2 the SelectedIndex remains 1.

How to solve this case?

Thanks!

Ermanni

Daniil
May 02, 2013, 6:38 AM
Please provide a test case.

ermanni.info
May 03, 2013, 1:19 AM
Hi!

Will no longer be necessary. Problems solved with the following code:



var menuClick = function (menu, item) {
App.pnlGrid.setTitle(Ext.String.format("Item selecionado: {0}", item.text));
var x;
for (x = 0; x < App.mpMovimento.menu.items.length; x++) {
if (App.mpMovimento.menu.items.get(x).id == item.id) break;
}
App.mpMovimento.setSelectedIndex(x);
App.direct.ReadData();
};


Thanks!

Ermanni