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.
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:
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?
A bit more info. I have a custom tree that builds a tree using code similar to this:
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:
Is this the correct way to do it, or am I missing something that makes it plug in without the need to re-sync?
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
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
is working on a reply...