I created my own custom Umbraco section. In this section are some nodes, but now I would like to add childnodes to these nodes. Currently I have the following source code:
Wow the code doens't look good. We really need an edit button and adding images would also be nice. Here is an example about how I would like to have my custom tree. I would like it to be the same as the pacakge node in the developer section. Here is a screenshot: http://img199.imageshack.us/img199/5683/packagef.jpg
and also, Aaron wrote an article about creating a custom tree dataprovider which I myself have used as inspiration for creating a custom tree with child nodes and everything else that you would expect from an umbraco tree.
From the WIKI page here is how to create multiple child node levels (main difference from creating a single level is highlighted in bold):
public override void Render(ref XmlTree tree) {
Dictionary.DictionaryItem[] tmp; //this.id is set when the tree.aspx creates this object. //It is the nodeID that is passed in via the tree service parameters (i.e. the query string) //this checks if the id is the StartNodeID (root node), if it’s not then this will //look up the child nodes for the current dictionary item. if (this.id == this.StartNodeID) tmp = Dictionary.getTopMostItems; else tmp = new Dictionary.DictionaryItem(this.id).Children;
foreach (Dictionary.DictionaryItem di in tmp) { XmlTreeNode xNode = XmlTreeNode.Create(this); xNode.NodeID = di.id.ToString(); xNode.Text = di.key; xNode.Action = string.Format("javascript:openDictionaryItem({0});", di.id); xNode.Icon = "settingDataType.gif"; xNode.OpenIcon = "settingDataType.gif"; //if there is no children, then set the source to an empty string //this will ensure that there is no expand button for this node when it is //rendered. Otherwise, set the source to the tree service url by using //the BaseTree’s GetTreeServiceUrl method xNode.Source = di.hasChildren ? this.GetTreeServiceUrl(di.id) : ""; tree.Add(xNode); } }
I'm trying to do this same thing however i'm not having much luck. The wiki page doesn't exist however i did come across the code sample on another url. But then that isn't really clear. I understand that assigning 'something' to the Source property will add the dropdown arrow to the tree node however i can't seem to find where i render the child nodes. Also, i get a null reference exception when i try to call this.GetTreeServiceUrl() (with or with a parameter).
I've got another question related to child nodes in a custom section. I've succeeded in adding child nodes, but now I would like the child nodes to expand immediately when the page is first loaded. Is this even possible because none of the other umbraco sections expand their childs when the page is loaded.
Thanks for reply slace! If I need to implement some javascript to expand the trees do I really need to modify the core of Umbraco? It's about a custom section with custom pages. Can't I place the javascript inside the custom pages? Does anybody know which function I need to call to expand the trees?
@ sas7: As you can see in the example it says foreach (Dictionary.DictionaryItem di in tmp). This means tmp probably contains an array of DictionaryItems.
Add child nodes to custom Umbraco section
Hello,
I created my own custom Umbraco section. In this section are some nodes, but now I would like to add childnodes to these nodes. Currently I have the following source code:
Now I would like to add childnodes to one of the XmlTreeNode objects. How can I do this? A screenshot of my custom section can be found at: http://img32.imageshack.us/img32/5607/section.jpg.
Wow the code doens't look good. We really need an edit button and adding images would also be nice. Here is an example about how I would like to have my custom tree. I would like it to be the same as the pacakge node in the developer section. Here is a screenshot: http://img199.imageshack.us/img199/5683/packagef.jpg
Hi Jeroen,
You should take a look at the following WIKI page:
http://our.umbraco.org/wiki/reference/api-cheatsheet/tree-api---to-create-custom-treesapplications
and also, Aaron wrote an article about creating a custom tree dataprovider which I myself have used as inspiration for creating a custom tree with child nodes and everything else that you would expect from an umbraco tree.
http://www.aaron-powell.com/blog/july-2009/creating-custom-dataproviders-for-linq-to-umbraco.aspx
From the WIKI page here is how to create multiple child node levels (main difference from creating a single level is highlighted in bold):
public override void Render(ref XmlTree tree)
{
Dictionary.DictionaryItem[] tmp;
//this.id is set when the tree.aspx creates this object.
//It is the nodeID that is passed in via the tree service parameters (i.e. the query string)
//this checks if the id is the StartNodeID (root node), if it’s not then this will
//look up the child nodes for the current dictionary item.
if (this.id == this.StartNodeID)
tmp = Dictionary.getTopMostItems;
else
tmp = new Dictionary.DictionaryItem(this.id).Children;
foreach (Dictionary.DictionaryItem di in tmp)
{
XmlTreeNode xNode = XmlTreeNode.Create(this);
xNode.NodeID = di.id.ToString();
xNode.Text = di.key;
xNode.Action = string.Format("javascript:openDictionaryItem({0});", di.id);
xNode.Icon = "settingDataType.gif";
xNode.OpenIcon = "settingDataType.gif";
//if there is no children, then set the source to an empty string
//this will ensure that there is no expand button for this node when it is
//rendered. Otherwise, set the source to the tree service url by using
//the BaseTree’s GetTreeServiceUrl method
xNode.Source = di.hasChildren ? this.GetTreeServiceUrl(di.id) : "";
tree.Add(xNode);
}
}
- Morten
Thank your Morten! This is just what I needed.
Hi
I'm trying to do this same thing however i'm not having much luck. The wiki page doesn't exist however i did come across the code sample on another url. But then that isn't really clear. I understand that assigning 'something' to the Source property will add the dropdown arrow to the tree node however i can't seem to find where i render the child nodes. Also, i get a null reference exception when i try to call this.GetTreeServiceUrl() (with or with a parameter).
Regards
Sean
This wiki page may help http://our.umbraco.org/wiki/reference/backoffice-apis/tree-api---to-create-custom-treesapplications
forget my last post - its been a long day! :)
i understand how it works now.
I've got another question related to child nodes in a custom section. I've succeeded in adding child nodes, but now I would like the child nodes to expand immediately when the page is first loaded. Is this even possible because none of the other umbraco sections expand their childs when the page is loaded.
I don't know if it is possible, you'd need to inject some JavaScript into the page which automatically calls the function to expand the tree.
It'd probably require quite a bit of hacking the core of Umbraco.
if you can tell about Dictionary.DictionaryItem[] tmp;
what values are stored in tmp?
Thanks for reply slace! If I need to implement some javascript to expand the trees do I really need to modify the core of Umbraco? It's about a custom section with custom pages. Can't I place the javascript inside the custom pages? Does anybody know which function I need to call to expand the trees?
@ sas7: As you can see in the example it says foreach (Dictionary.DictionaryItem di in tmp). This means tmp probably contains an array of DictionaryItems.
hi jeroen.,
how to load values into DictionaryItems..
is it default values or users can load the values?
Hello,
What about Custom menu actions?
I have my own section with a custom tree inside it. I want to manually add menu actions with this code:
This node has child nodes which are set via customer.source.
But I dont want to have these menu actions (that are set in the last two lines of my code) on child nodes of the customer node.
How can I prevent the child nodes having the same menu items as their parent?
Thanks!
@sas7 the tmp is filled by the next piece of code:
the 'this.id' is the id given at this code:
This way the user can load the values depending on what id he passes.
@jernej I used the following code to give the child nodes different actions:
This forum needs some updates or at least an edit button! The code above should be one single code block....
hi folks.,
i tried to create tree nodes here.. but its getting repeated
XmlTreeNode
xnode= XmlTreeNode.Create(this);
//node.NodeID = "1";//in remote db(umbracoUser2app)
xnode.Text = "custom services";
xnode.Action = "javascript:openBoard('Custom');";
xnode.OpenIcon = "folder_o.gif";
xnode.Icon = "folder.gif";
xnode.NodeType = "Custom";
xnode.Source = this.GetTreeServiceUrl();
here the node get repeated? any pointers?
It's currently impossible to expand child nodes immediately, but will this be possible in Umbraco 4.1 since the entire tree will be replaced?
hi folks.,
if you can post the example code of adding childnodes here as i still have difficulty in creating childnode
Thank you
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.