10 Answers, 1 is accepted
Hello Mikko,
One option that I can suggest is altering the LoadOnDemand method and programmatically set the ExpandMode to ClientSide and populate the nested children.
Attached you can find a simple example, that when expanding the "Products" node, loads its children and expands the "UI for ASP.NET AJAX" node also.
private static void PopulateNodeOnDemand(RadTreeNodeEventArgs e, TreeNodeExpandMode expandMode)
{
DataTable data = GetChildNodes(e.Node.Value);
foreach (DataRow row in data.Rows)
{
RadTreeNode node = new RadTreeNode();
node.Text = row["Title"].ToString();
node.Value = row["CategoryId"].ToString();
if (Convert.ToInt32(row["ChildrenCount"]) > 0)
{
if (node.Value == "2")
{
node.ExpandMode = TreeNodeExpandMode.ClientSide;
var args = new RadTreeNodeEventArgs(node);
PopulateNodeOnDemand(args, expandMode);
}
else
{
node.ExpandMode = expandMode;
}
}
e.Node.Nodes.Add(node);
}
e.Node.Expanded = true;
}
Regards,
Peter Milchev
Progress Telerik
Hello Peter,
Is there a way to "read" node depth, not value?
"if (node.Value == "2")"
Hello Mikko,
The RadTreeNode has the Level property you can use:
Regards,
Peter Milchev
Progress Telerik
Hello Peter,
Our problem is that we have so many nodes that it takes vary long time load those, over 15 sec.
When using ServerSide expand mode it's much faster, but we need to open first 2-3 node levels on page load. This works fine without using ServeSide expand mode. With it we cannot pre-open nodes.
Hi Mikko,
With this approach, the nodes are still not available on the time of rendering of the control and that's why the Level property does not work
If you keep using the ExpandMode.ServerSide approach, you can expand only the root node using this approach:
<script>
function OnClientLoad(tree, args) {
var item = tree.get_nodes().getItem(0);
item.set_expanded(true);
}
</script>
<telerik:RadTreeView RenderMode="Lightweight" OnClientLoad="OnClientLoad" ID="RadTreeView1" runat="server" Height="300px"
OnNodeExpand="RadTreeView1_NodeExpand">
</telerik:RadTreeView>
Regards,
Rumen
Progress Telerik
Hi Rumen,
We are getting closer, thanks.
Script only opens first node, not all root level nodes.
Best regards, Mikko
Hi Mikko,
You can expand all root items on load via the following script:
<script>
function OnClientLoad(tree, args) {
var items = tree.get_allNodes();
for (var i = 0; i < items.length; i++) {
var item = items[i];
item.set_expanded(true);
}
}
</script>
<telerik:RadTreeView OnClientLoad="OnClientLoad" ...
You can also check the level of the respective item with the items[0].get_level() method.
Regards,
Rumen
Progress Telerik
Hi!
I have a another question/problem.
If user opens a node (OnNodeExpand="RadTreeView1_NodeExpand") and closes and re-opens it, there are double entiries of all child nodes. So, each time node is closed and opened, childs are added. It there a solution for this?
Best regards, Mikko
Hello Mikko,
The sample project that I have attached in my reply from March 2, 2020, this duplicate issue is not present.
Please modify the project so that it implements your logic and replicates the issue and send it back to us as an attachment to an official support ticket.
That would allow us to investigate your exact scenario and provide more accurate and specific suggestions.
Regards,
Peter Milchev
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.
Hello,
I looked at your sample and found a solution. Thanks!
Mikko