Hello,
Is there a way to add a node to another node while preserving all the children of the node being added?
In javascript.
Hi,
I think you are looking for something like this:
function AddChildNodesRecursive(childNode, parentNode) {
var newChild = parentNode.addChild(childNode.getText());
if (childNode.hasChildren()) {
var children = childNode.getChildNodes();
for (c in children) {
var childSubNode = children[ c ];
AddChildNodesRecursive(childSubNode, newChild);
}
Matthew,
I thought I tackled a similar problem a while back. I have a system built around the structure of the Infragistics demos. That is, a WebTree on the left for navigation, a title bar, a footer, and a contents page.
Basically, the contents page is generally a grid that allows the customer to then select a person or a piece of inventory or whatever.
However, one of the options I need is to allow the operator to right-click on a grid selector and select 'Move to Folder' to move the individual to another tree node. Since the content page is in a different frame (and is a different asp.net page) I wanted to popup a form, populate the WebTree on that form with the contents of the WebTree I use as a navigation tool - the one in the left frame.
I 'accomplished' this by saving the WebTree in the left menu frame to a Session variable. I then retrieved that WebTree object in the popup form and used the .AddRange() to quickly populate the tree on the popup form. It all looked good, seemed to work. However, I have used the same concept in a new more complex tree and it flubs. Basically, if the customer selects a node at the same level as the initial selection than the 'Selected Node' remains the initial node. If, however, the customer selects a node outside of the initial node's siblings it seems to work a bit better.
My guess is that restoring a tree from a Session variable may not be as reliable as I thought. And, AddRange() may be doing some whoop-di-da for performance reasons and not really fully adding all the nodes - but, instead keying on the sibling nodes. More useful for an On Demand load.
Clear as mud, eh.
Confusing.
As an alternative, could I use the tree and nodes saved in the session to initiate recursive Add()s similar to the above? Or, is saving a WebTree to a session unreliable?
Thanks Rumen,
Using the XML didn't really help - but, it did cause a bit more piece of mind. I can actually see things a bit clearer.
What actually was happening is that I hadn't trapped the server side click event - and, still has some client side click events going off into the internetosphere. Uuuuggggghhhhhh. I had copied the tree. So, basically, the control displayed as if I had clicked a node, but the selected node remained the old one (set on initial page load).
For some reason your examples led me to look there. So again thanks. And, special thanks for the information on the new control. I think future upgrades will use it.
Hello Roger,
Maybe you can use the built in export/import from XML methods to save the state of the tree instance automatically instead of manually iterating / adding nodes using AddRange - this way it could be easier and hopefully it will take care of the problems you are having.
Read/WriteXmlString are documented here:
http://help.infragistics.com/Help/NetAdvantage/NET/2008.1/CLR2.0/html/Infragistics2.WebUI.UltraWebNavigator.v8.1~Infragistics.WebUI.UltraWebNavigator.UltraWebTree~WriteXmlString.html
http://help.infragistics.com/Help/NetAdvantage/NET/2008.1/CLR2.0/html/Infragistics2.WebUI.UltraWebNavigator.v8.1~Infragistics.WebUI.UltraWebNavigator.UltraWebTree~ReadXmlString.html
Also, I can suggest our brand new product, WebSplitter, in which you can have left / right resizable panes (and in fact, any other configuration, including nested splitters) - the benefit is that end-users can resize it and it still acts as the same page (not several pages as in frames) - much easier from end-user/developer point of view and a lot of additional benefits like better SEO, etc.
Online WebSplitter sample can be found here:
http://samples.infragistics.com/2008.1/webfeaturebrowser/WebSplitter/SplitterSampleNestedPanes.aspx?View=Overview