Thanks to those on Twitter that pointed me towards Dirks post on this subject matter however I am not really understanding how to achieve my goal, perhaps I am being particularly thick and missing something obvious but if anyone can shed some light on the solution I would appreciate it. I have "borrowed" some code from the Umbraco source to try and achieve my goal and here are my the two methods that are not currently rendering the required results:
When my tree is rendered I end up with a Customers node and then nodes representing each letter of the alphabet also in the root. What I actually need is as follows:
Companies - a - b - c - ... - z
Customers - a - b - c - ... - z
Also what currently appears to happen is when I expand a node such as "a" I get a copy of all the root nodes as children.
Render() method gets hit for each node that is expandable, so your code fires each time meaning you get the duplicate structure
Must first add a check to find out what node you'll be rendering. As per my article, I've done this by checking the NodeKey property. If that's empty, then I'm dealing with "top level" nodes. And all other nodes do get a "special" NodeKey property so I can differentiate between the different nodes.
Also, should be using TreeService instead of setting the url yourself (some sample code can also be found on that specific article)
FWIW, here is what I use in the Commerce for Umbraco tree to create the same structure you describe:
namespace CommerceForUmbraco.adminSection.trees { /// <summary> /// Renders a Tree containing all Products /// </summary> public class loadProductTree : BaseTree { public loadProductTree(string application) : base(application) { }
public override void RenderJS(ref StringBuilder Javascript) { Javascript.Append( @" function openProduct(id) { parent.right.document.location.href = 'commerce/editProduct.aspx?p=' + id; } "); }
public override void Render(ref XmlTree tree) {
string letter = string.Empty; if (HttpContext.Current.Request.QueryString.ToString().IndexOf("letter") >= 0) { letter = HttpContext.Current.Request.QueryString.Get("letter"); }
if (letter != string.Empty) { // get collection values Commerce.Common.ProductCollection products = null;
if (letter == "Others") { SubSonic.InlineQuery qry = new SubSonic.InlineQuery(); products = new ProductCollection(); products = qry.ExecuteAsCollection<ProductCollection>("select * from dbo.CSK_Store_Product where substring(productname, 1, 1) in ('1','2','3','4','5','6','7','8','9','0')"); } else products = new ProductCollection().Where(Product.Columns.ProductName, SubSonic.Comparison.Like, letter + "%").OrderByAsc("ProductName").Load();
Paul/Dirk thanks for your patience and assistance your help has been invaluable and I now have my tree structured exactly as required. Sometimes I just need a little nudge in the right direction and the light comes on ;)
Paul, with respect, as you are already on the Core team I will mark Dirk's answer as the solution if thats ok.
Problems adding child nodes to custom tree node
Thanks to those on Twitter that pointed me towards Dirks post on this subject matter however I am not really understanding how to achieve my goal, perhaps I am being particularly thick and missing something obvious but if anyone can shed some light on the solution I would appreciate it. I have "borrowed" some code from the Umbraco source to try and achieve my goal and here are my the two methods that are not currently rendering the required results:
When my tree is rendered I end up with a Customers node and then nodes representing each letter of the alphabet also in the root. What I actually need is as follows:
Companies
- a
- b
- c
- ...
- z
Customers
- a
- b
- c
- ...
- z
Also what currently appears to happen is when I expand a node such as "a" I get a copy of all the root nodes as children.
Thanks in advance.
Simon
Simon,
Render() method gets hit for each node that is expandable, so your code fires each time meaning you get the duplicate structure
Must first add a check to find out what node you'll be rendering. As per my article, I've done this by checking the NodeKey property. If that's empty, then I'm dealing with "top level" nodes. And all other nodes do get a "special" NodeKey property so I can differentiate between the different nodes.
Also, should be using TreeService instead of setting the url yourself (some sample code can also be found on that specific article)
Let me know if you need more help
Cheers,
/Dirk
Simon -
FWIW, here is what I use in the Commerce for Umbraco tree to create the same structure you describe:
Paul/Dirk thanks for your patience and assistance your help has been invaluable and I now have my tree structured exactly as required. Sometimes I just need a little nudge in the right direction and the light comes on ;)
Paul, with respect, as you are already on the Core team I will mark Dirk's answer as the solution if thats ok.
is working on a reply...