[CLOSED] MenuPanel dymanic items are not selected

  1. #1

    [CLOSED] MenuPanel dymanic items are not selected

    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:
    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.
    Last edited by Daniil; May 03, 2013 at 3:58 AM. Reason: [CLOSED]
  2. #2
    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();
  3. #3
    Hi!

    Realized the changes suggested and the problem was solved!

    Thanks!

    Ermanni
    Last edited by ermanni.info; May 01, 2013 at 1:51 PM.
  4. #4
    I retested, it works for me.

    How does your test case look now?
  5. #5
    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
  6. #6
    Please provide a test case.
  7. #7
    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

Similar Threads

  1. Replies: 0
    Last Post: Mar 12, 2012, 7:26 AM
  2. MenuPanel update items from javascript
    By Paul D in forum 1.x Help
    Replies: 2
    Last Post: Sep 23, 2010, 2:12 PM
  3. Replies: 5
    Last Post: Nov 02, 2009, 12:31 PM
  4. MenuPanel dynamic items add
    By yarlenvas in forum 1.x Help
    Replies: 3
    Last Post: Mar 11, 2009, 2:30 AM
  5. [CLOSED] MenuPanel selected
    By Zarzand in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Dec 03, 2008, 9:15 AM

Tags for this Thread

Posting Permissions