RadzenTree Update children

Hi.

I have a RadzenTree on the page with data which is multilanguage and dropdown for language selection. Data is loaded in the tree control on demand - no issues with that.

Children data is loaded with the code

private async Task OnTreeNodeExpand(TreeExpandEventArgs args)
{
	if (args.Value is MyTreeItem item)
	{
		args.Children.Data = ##Getting data here
		args.Children.TextProperty = "NamePlural";
		args.Children.HasChildren = ((i) => ((MyTreeItem)i).HasChildren);
		args.Children.Template = TreeItemTemplate;
	}
}

When i am changing language selection in drop down, i am reloading the root level data. Root level items are updated on UI, but old children are still there.
Any ideas how can i remove them or reload in a proper way?

Example.

  1. Original tree in English
  2. After switching to French, root level is get updated, but opened children not.
  3. This is how tree is looking, if i will collapse "First plural" node and open it again while French language is active.

Any suggestions?

P.S. I have also tried to keep a track of loaded children data in the dictionary, and reload all of them on the language changed. Tree behavior is the same as described above :frowning:

private async Task OnTreeNodeExpand(TreeExpandEventArgs args)
{
		if (args.Value is MyTreeItem item)
		{
			if (_loadedTreeItems.ContainsKey(item.Id))
			{
				_loadedTreeItems[item.Id] = ##Loading data here##
			}
			else
			{
				var childrenData = ##Loading data here##
				_loadedTreeItems.Add(item.Id, childrenData);
			}
			args.Children.Data = _loadedTreeItems[item.Id];
			args.Children.TextProperty = "NamePlural";
			args.Children.HasChildren = ((i) => ((MyTreeItem)i).HasChildren);
			args.Children.Template = TreeItemTemplate;
		}
}

Hi @tau,

We will need some minimal example that reproduces the problem.

Thank you for reply.
Will try to do a separate solution with hard coded data and upload it somewhere.
For now i "got solved" the issue by doing a trick, when language is changed i am doing
_rootLevelData = null;
_rootLevelData = ###loading data###
Such a way all data nodes are collapsed and root level is reloaded.

@korchev @enchev
I have commited demo project on github https://github.com/taukiev/RadzenBlazorIssues and have invited https://github.com/akorchev and https://github.com/enchev users.

I hope it will be understandable.
There is one more page with Selected issue. When Selected set programmatically, with a mouse click on the node it is missing "ui-treenode-content-selected" class. It might be i do something wrong.

Thank you in advanced for your help.

Thanks. We will take a look some time next week.

1 Like

error
RadzenTreeTest.zip (685.4 KB)

I have also run into this issue. My $0.02 is that the Blazor 'diff' engine is unable to see that the screen should be updated?

Can you post more code as to exactly how you implemented this? Thanks!

I've made some changes in the treeview so a node renders its children if its Value property changes and the node was expanded. The fix will be available with the next Radzen release.

1 Like

Here is the solution which works with dummy hard coded data
RadzenBlazorIssues.zip (225.2 KB)
I hope it helps.

1 Like

:partying_face: Great great news. Thank you a lot.

It seems that RadzenTree will not load child nodes if AsNoTracking() is enabled, e.g.

   RootMarkets = rootMarkets
                            .OrderByDescending(x => x.MarketTypeId)
                            .ThenBy(x => x.Name);
                            //LOW: breaks loading of child nodes?
                            //.AsNoTracking();               

To clarify, when expanding a node that should have children, the OnExpand event for the tree never fires.

Make sure that the HasChildren setting returns true for those nodes.

1 Like