We have a web tree and want to give the user the ability to check the parent node and have it automatically check the child nodes. The only problem is that we are using demand load. We can get around most issues except for the following scenario:
We have JavaScript like in the example given at http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=4941. The only thing we added was "if (bCheck && !childNodes[n].getExpanded()) { childNodes[n].setExpanded(true); }". This way we will expand the children to expose the grandchildren (since they are only loaded on demand). On the server side DemandLoad event we check if the node is checked and if so, raise the OnDemandLoad(NEWLY_ADDED_NODE) method off the web tree so we load all the child nodes down the chain. The problem is that when we are in the DemandLoad server-side event, it doesn't recognize that the node has been checked.
Any help would be greatly appreciated. Thanks
Good day!
We have the similar problem with the DemanLoad:
We want generate multilevel tree with the DemandLoad. We are normally load first and second level, but weird - when we try to load third level, in e.Node.Parent we have "null" and Text is also "null". What could this be?
Thank you!
Source:
protected void Page_Load(object sender, EventArgs e) { UltraWebTree1.Nodes.Add("Test").ShowExpand = true; UltraWebTree1.Nodes.Add("One").ShowExpand = true; } protected void UltraWebTree1_DemandLoad(object sender, Infragistics.WebUI.UltraWebNavigator.WebTreeNodeEventArgs e) { if(e.Node.Text == "Test") { e.Node.Nodes.Add("Test").ShowExpand = true; e.Node.Expanded = true; } if(e.Node.Text == "One") { e.Node.Nodes.Add("One").ShowExpand = true; e.Node.Expanded = true; } }
What kind of load-on-demand setting are you using?
If you're using ManualSmartCallbacks, then this would be expected. During the AJAX callbacks where the DemandLoad event is raised, only the data path of the node is passed from the client to the server (as e.DataPath), and other values will be null. This isn't always obvious when you're adding nodes to the second level of the tree, because the first level can be populated during the callback in some circumstances; second and later levels won't be pouplated.
You should put enough information in the DataPath so that you know exactly where in your hierarchy the node belongs.
Thank you, for your answer
Yes, we are using ManualSmartCallbacks.
So in this case, could I add new node at the third and lower levels in this mode (ManualSmartCallbacks)? Because, as I understand, I don't have full node objects on the server side?
What is your advice to build manual multilevel tree, with the load-on-demand setting? I see now just one solution - manually create datasource with relations, but in this case i will lose all advantages of the load-on-demand...
You don't need to bind your tree to the whole data source. As you mention, that would indeed defeat much of the purpose of using load-on-demand in the first place.
I believe there's a sample project that uses ManualSmartCallbacks in the samples installer, but I don't currently have access to a system where I can quickly find where it is. Instead, I'll describe the general approach.
My suggestion is to think of the "DataPath" property as the text you'd put in address bar in Windows Explorer. The address bar allows you to uniquely identify the complete path of a file on your system by giving a list of all of its parent directories, all the way up to the drive. For your tree, think of your "drive" as a root node, and think of each sub-folder as a "child node".
When initially building the root nodes of your tree, be sure you set the DataPath property to something that uniquely identifies that node within the collection of root nodes (not necessarily in the whole tree. For each child node, you'll append the parent node's data path, some separator, and then a identifier that is unique within the collection of related child nodes.
For example, say I've got a three level tree. At the root and at each set of child nodes, I'll have three nodes, each with the text One, Two, and Three. Since the text of my nodes are unique, I'll use that for my DataPath. For my root nodes collection, I'll create three nodes, one with a Text of "One" and a DataPath of "One", one with "Two" and "Two", and one with "Three" and "Three".
Where this becomes helpful is in the DemandLoad event. I can check "e.DataPath" to see where in the hierarchy I'm at, in case I need to select different data to get at the next level (in this example, I don't need to do this check, because I'm adding the same three nodes at every level). I can then create new nodes to display, but the most important thing I need to do is to set the new nodes' DataPath properties. For instance, in C#:
using Infragistics.WebUI.UltraWebNavigator;...private void UltraWebTree1_DemandLoad(object sender, WebTreeNodeEventArgs e){ Node newNode = new UltraTreeNode(); newNode.Text = "One"; newNode.DataPath = e.Node.DataPath + "/" + newNode.Text; e.Node.Nodes.Add(newNode);}
This code would be repeated to add the "Two" and "Three" nodes, as well as to set any other desired properties. The result is that each node has slash-delimited text that identifies where in the hierarchy the node exists. Underneath the "One" node I have nodes with DataPath values of "One/One", "One/Two", and "One/Three". Underneath the "One/One" node I have "One/One/One", "One/One/Two", and "One/One/Three", and so on.
This example could be extended to any arbitrary number of levels without changing the approach.