Copied to clipboard

Flag this post as spam?

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


  • Tim 1193 posts 2675 karma points MVP 3x c-trib
    May 20, 2014 @ 15:21
    Tim
    0

    How to Select Tree Item in Custom Tree

    Hi,

    I have created a custom tree service that populates a tree from a custom database table. I've hooked it up to an edit view and a delete action successfully, but the one thing I cannot get to work is for the tree to show the currently selected item.

    Has anyone managed to get that to work? The code for the tree looks like it should be selecting the tree item, but it never gets selected. If I refresh the node in the tree on edit in the edit view, the item shows up as selected, but not when I click on it. I'd quite like it to select the current item if at all possible, like the core trees do.

    Anyone know how to make this work?

  • Tim 1193 posts 2675 karma points MVP 3x c-trib
    Jun 24, 2014 @ 17:29
    Tim
    1

    A bit more info. I have a custom tree that builds a tree using code similar to this:

    protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings)
        {
            //check if we're rendering the root node's children
            if (id == Constants.System.Root.ToInvariantString())
            {
                var controller = new PersonApiController();
                var nodes = new TreeNodeCollection();
    
                //get each person from the DB and add a tree item for them
                foreach (var person in controller.GetAll())
                {
                    var node = CreateTreeNode(person.Id.ToString(CultureInfo.InvariantCulture), id, queryStrings, person.Name, "icon-user", false);
    
                    //if the person is drunk, change their tree icon
                    if (person.IsDrunk)
                        node.Icon = "icon-wine-glass";
    
                    nodes.Add(node);
    
                }
                return nodes;
            }
    
            //this tree doesn't suport rendering more than 1 level
            throw new NotSupportedException();
        }
    

    When I click on one of the tree items, I'd expect the tree item to become highlighted, like the content tree items and the items in the other trees. The $scope.currentNode variable gets populated, but the tree item isn't highlighted. the only way I've found to get the tree item to highlight, is to call some code like this in my controller:

    navigationService.syncTree({ tree: 'peopleTree', path: ["-1", $scope.person.id], forceReload: false });
    

    Is this the correct way to do it, or am I missing something that makes it plug in without the need to re-sync?

  • Zdenek 1 post 21 karma points
    Jul 27, 2014 @ 22:36
    Zdenek
    0

    Hello ,

     

    I have the same problem. Furthermore I would like to know how to expand the path for selected node for multi-level menus. 

     

    Let's user knows already url www.host.com/umbraco/Product/5662

    but in the menu it's under 

    Products

    Car

    BMW X5 (Id 5662)

     

     

    Thank you for reply

     

  • John Sharp 20 posts 110 karma points
    Apr 12, 2016 @ 15:12
    John Sharp
    0

    Hi there,

    I'm coming to this a bit late but was there an update to this post please as I'm having this issue in 7.4.1.

    Many thanks,

    John

Please Sign in or register to post replies

Write your reply to:

Draft