Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Louis Ferreira 69 posts 266 karma points
    Sep 14, 2022 @ 08:52
    Louis Ferreira
    0

    How do I : Create a Custom Tree Menu Action on 'Tree Title'

    Hello, I've created a custom section with custome tree by following the documentation. All is fine and looking good, but what I'd like to know is how do I add a Action Menu to the top most (Tree Title) node? For example, on the Content section, hovering on the 'Content' title you will get the elipses that allows you to create new documents. enter image description here

    I'd like to replicate this functionality on my top level/title node to allow me to create new root nodes... enter image description here

    My guess is that there must be something in the 'CreateRootNode() method to do this? Any pointers?

    TIA

  • Johannes Lantz 156 posts 839 karma points c-trib
    Sep 17, 2022 @ 15:57
    Johannes Lantz
    0

    Hello!

    You are looking for the GetMenuForNode() method! You can find examples here.

    I have done something like this:

        protected override MenuItemCollection GetMenuForNode(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))] FormDataCollection queryStrings)
        {
            var menu = new MenuItemCollection();
    
            if (id == Root.ToInvariantString())
            {
                menu.Items.Add<ActionNew>(Services.TextService, true).NavigateToRoute($"/foo/bar/edit/-1?create");  
            }
    
            return menu;
        }
    

    Hope this gets you on the right track! :)

    //Johannes

  • Louis Ferreira 69 posts 266 karma points
    Sep 18, 2022 @ 05:23
    Louis Ferreira
    0

    I already have an implementation of that method as follows:

     protected override ActionResult<MenuItemCollection> GetMenuForNode(string id, FormCollection queryStrings)
        {
            // create a Menu Item Collection to return so people can interact with the nodes in your tree
            var menu = _menuItemCollectionFactory.Create();
    
            if (id == Constants.System.Root.ToInvariantString())
            {
                // root actions, perhaps users can create new items in this tree, or perhaps it's not a content tree, it might be a read only tree, or each node item might represent something entirely different...
                // add your menu item actions or custom ActionMenuItems
                menu.Items.Add(new CreateChildEntity(LocalizedTextService));
                // add refresh menu item (note no dialog)
                menu.Items.Add(new RefreshNode(LocalizedTextService, true));
            }
            else
            {
                menu.Items.Add<ActionNew>(LocalizedTextService, true, opensDialog: true);
                menu.Items.Add<ActionUpdate>(LocalizedTextService, true, opensDialog: true);
                menu.Items.Add<ActionDelete>(LocalizedTextService, true, opensDialog: true);
                menu.Items.Add(new RefreshNode(LocalizedTextService, false));
            }
    
    
            return menu;
        }
    

    but... it never gets called by the runtime because there is no action associated with that node (id = -1) and is evident by the fact that there are no elipses when you hover over it, and that's the essence of this question. The other 'child' nodes work just fine with the custom action menus.

  • Johannes Lantz 156 posts 839 karma points c-trib
    Sep 18, 2022 @ 10:44
    Johannes Lantz
    1

    Ahhh! Sorry my bad! I read it wrong.

    In that case you are correct. It has something to do with the CreateRootNode method. It should be this line that removes the elipses root.MenuUrl = null;. I don't know if just removing that line show elipses.

    //Johannes

  • Nijaz Hameed 38 posts 173 karma points
    Aug 08, 2024 @ 07:26
    Nijaz Hameed
    0

    It's worked for me, thanks Johannes

Please Sign in or register to post replies

Write your reply to:

Draft