[CLOSED] How to dynamically load my menu in MVC

  1. #1

    [CLOSED] How to dynamically load my menu in MVC

    Hi,
    I'm trying to load my menu button dynamically in mvc. But I can't Fire DirectAction with Loader like this example : https://examples2.ext.net/#/Toolbar/Menu/Dynamic_Items/

    Could you please give me an example ?
    Last edited by Baidaly; Nov 27, 2013 at 7:54 PM. Reason: [CLOSED]
  2. #2
    Quote Originally Posted by Tactem View Post
    Hi,
    I'm trying to load my menu button dynamically in mvc. But I can't Fire DirectAction with Loader like this example : https://examples2.ext.net/#/Toolbar/Menu/Dynamic_Items/

    Could you please give me an example ?
    I found a way with ContentResult. But I want to add an fonctionality i.e I want to reload the menu everytime I click it. How can I do that ?
    Last edited by Tactem; Nov 26, 2013 at 3:08 PM.
  3. #3
    Hello!

    It depends how you load the menu. Could you provide a sample how you load it now?

    And what do you want to reload? MenuItems? Basically, you need to send a request to get new items, remove all current items (http://docs.sencha.com/extjs/4.1.3/#...thod-removeAll) and add new items (http://docs.sencha.com/extjs/4.1.3/#...enu-method-add)
  4. #4
    Quote Originally Posted by Baidaly View Post
    Hello!

    It depends how you load the menu. Could you provide a sample how you load it now?

    And what do you want to reload? MenuItems? Basically, you need to send a request to get new items, remove all current items (http://docs.sencha.com/extjs/4.1.3/#...thod-removeAll) and add new items (http://docs.sencha.com/extjs/4.1.3/#...enu-method-add)
    I just want to load the menu everytime I click on it because the content is updated by another thread so if I click the menu I want to reload (call again the action which get data from database)

    here is th e example of my code :
                            Html.X().Button(Model.ConfigFavButton)
                            .Icon(Icon.Star)
                            .Text("Menu"),
    I construct my menu in code behind through button.Config
    public Button.Config GetFavoriteButtonConfig(int clientId, int userId)
            {
    Button.Config favButtonConfig = new Button.Config 
                {                
                };
    Menu menu = new Menu();
    MenuItem item = new MenuItem();
    item.IconCls = "x-loading-indicator";
    item.CanActivate = false;
    item.HideOnClick = false;
    menu.Add(item);
    menu.Loader = new ComponentLoader { Mode = LoadMode.Component, Url = "LoadMenu", RemoveAll = true};
    favButtonConfig.Menu.Add(menu);            
                return favButtonConfig;
    }
    public ContentResult LoadMenu()
    {
    List<Ext.Net.MenuItem> items = new List<Ext.Net.MenuItem>();
    ... construction of menuItems through data from database...
    return Content(ComponentLoader.ToConfig(items));
    }
    I want to call my LoadMenu action everytime I click on the button. How can I do that evenif I do not have to use Loader ?
  5. #5
    Quote Originally Posted by Tactem View Post
    I just want to load the menu everytime I click on it because the content is updated by another thread so if I click the menu I want to reload (call again the action which get data from database)

    here is th e example of my code :
                            Html.X().Button(Model.ConfigFavButton)
                            .Icon(Icon.Star)
                            .Text("Menu"),
    I construct my menu in code behind through button.Config
    public Button.Config GetFavoriteButtonConfig(int clientId, int userId)
            {
    Button.Config favButtonConfig = new Button.Config 
                {                
                };
    Menu menu = new Menu();
    MenuItem item = new MenuItem();
    item.IconCls = "x-loading-indicator";
    item.CanActivate = false;
    item.HideOnClick = false;
    menu.Add(item);
    menu.Loader = new ComponentLoader { Mode = LoadMode.Component, Url = "LoadMenu", RemoveAll = true};
    favButtonConfig.Menu.Add(menu);            
                return favButtonConfig;
    }
    public ContentResult LoadMenu()
    {
    List<Ext.Net.MenuItem> items = new List<Ext.Net.MenuItem>();
    ... construction of menuItems through data from database...
    return Content(ComponentLoader.ToConfig(items));
    }
    I want to call my LoadMenu action everytime I click on the button. How can I do that evenif I do not have to use Loader ?
    Hello somebody there ?
  6. #6
    There setting for the Loader helps.

    Here is a full example.

    View
    @{
        var X = Html.X(); 
    }
    
    <!DOCTYPE html>
    <html>
    <head>
        <title>Ext.Net.MVC v2 Example</title>  
    </head>
    <body>
        @X.ResourceManager()
    
        @(X.Button()
            .Text("Menu")
            .Menu(
                X.Menu()
                    .Loader(
                        X.ComponentLoader()
                            .Mode(LoadMode.Component)
                            .Url(Url.Action("GetButtons"))
                            .RemoveAll(true)
                            .TriggerEvent("show")
                            .ReloadOnEvent(true)
                    )
                    .Items(X.MenuItem())
            )
        )
    </body>
    </html>
    Controller
    public ActionResult GetButtons()
    {
        Button[] buttons = new Button[]
        {
            new Button() 
            {
                Text = "Button 1 " + DateTime.Now.Second
            },
            new Button() 
            {
                Text = "Button 2 " + DateTime.Now.Second
            }
        };
    
        return this.Content(ComponentLoader.ToConfig(buttons));
    }
  7. #7
    Quote Originally Posted by Daniil View Post
    There setting for the Loader helps.

    Here is a full example.

    View
    @{
        var X = Html.X(); 
    }
    
    <!DOCTYPE html>
    <html>
    <head>
        <title>Ext.Net.MVC v2 Example</title>  
    </head>
    <body>
        @X.ResourceManager()
    
        @(X.Button()
            .Text("Menu")
            .Menu(
                X.Menu()
                    .Loader(
                        X.ComponentLoader()
                            .Mode(LoadMode.Component)
                            .Url(Url.Action("GetButtons"))
                            .RemoveAll(true)
                            .TriggerEvent("show")
                            .ReloadOnEvent(true)
                    )
                    .Items(X.MenuItem())
            )
        )
    </body>
    </html>
    Controller
    public ActionResult GetButtons()
    {
        Button[] buttons = new Button[]
        {
            new Button() 
            {
                Text = "Button 1 " + DateTime.Now.Second
            },
            new Button() 
            {
                Text = "Button 2 " + DateTime.Now.Second
            }
        };
    
        return this.Content(ComponentLoader.ToConfig(buttons));
    }
    I'll try this and keep you inform.
  8. #8
    Quote Originally Posted by Tactem View Post
    I'll try this and keep you inform.
    GREAT, thank you very much Daniil you can close the tread.

Similar Threads

  1. Replies: 1
    Last Post: Dec 12, 2012, 3:21 PM
  2. Replies: 8
    Last Post: Jul 29, 2012, 10:58 AM
  3. Ext .net Menu Panel dynamically created
    By garag in forum 1.x Help
    Replies: 1
    Last Post: Oct 14, 2011, 9:50 AM
  4. Add items to menu dynamically
    By sunshine in forum 1.x Help
    Replies: 5
    Last Post: Mar 10, 2011, 6:44 PM
  5. Array of Strings to Menu Dynamically
    By rthiney in forum 1.x Help
    Replies: 8
    Last Post: Nov 18, 2009, 4:44 AM

Tags for this Thread

Posting Permissions