Add a Node to root is not visible
Hy all,
I work on a server-side blazor solution. I want to add nodes to a treeview by code. My Treeview component implementation is below:
<SfTreeView @ref="treeView" TValue="CommessaElementVM" AllowDragAndDrop="true">
<TreeViewFieldsSettings DataSource="@vm.ElementListVM" Id="RowGuid" Text="Descrizione"
Child="@("Children")" TValue="CommessaElementVM" Selected="IsSelected"
Expanded="Expanded"></TreeViewFieldsSettings>
<TreeViewEvents TValue="CommessaElementVM" NodeSelected="OnSelect" NodeExpanding="OnExpanding" NodeDropped="OnNodeDropped" />
</SfTreeView>
While CommessaElementVM class is:
public class CommessaElementVM
{
public string RowGuid { get; set; }
public string GuidParent { get; set; }
public string Descrizione { get; set; }
public bool Expanded { get; set; }
public bool IsSelected { get; set; }
public bool HasChildren { get; set; }
public bool IsRootElement => string.IsNullOrEmpty(GuidParent);
private List<CommessaElementVM> _Children = new List<CommessaElementVM>();
public List<CommessaElementVM> Children
{
get
{
return _Children;
}
set
{
HasChildren = true;
_Children = value;
}
}
}
vm.ElementListVM is a List<CommessaElementVM> implemented in my MVVM viewmodel.
As you can see data Nodes is loaded on demand by code. When I want to add a node I use a SfDialog to force user to insert others data. When User click on Save button of SfDialog my code insert a node. If node is child of an existing parent node all work fine and child node is showed on treeview. This is not true if I try to add a root Node. In this case I add a new element in vm.ElementListVM (DataSource) but this node is not visible on treeview. I tried with treeView.RefreshNode(..), treeView.Refresh(), StateHasChanged methods but it does not work. The new node showed only if I refresh my browser.
What should I do to add a root node by code?
thanks.
Rolando
SIGN IN To post a reply.
3 Replies
1 reply marked as answer
MK
Muthukrishnan Kandasamy
Syncfusion Team
July 20, 2020 12:14 PM UTC
Hi Rolando,
Thanks for contacting Syncfusion support.
We have validated your reported problem, we suspect that you have added new tree node within another first level node. If you are expecting to add a new node on first level of nodes, then we need to add the nodes without any target then it will be added as root level node. Please refer the below code block.
|
public void Add()
{
MailItem[] Mail = new MailItem[] { new MailItem { Id = "04-01", FolderName = "New Folder" } };
treeView.AddNodes(Mail);
} |
We have prepared sample for your convenience, in this sample we have added root node using button click event.
|
Description |
Link |
|
Getting started |
|
|
CRUD operation in local data |
|
|
API reference |
|
|
Live demo |
If you are still facing the issue, kindly share the following details.
1. If facing any console error, share the screenshots.
2. If possible, please share the issue reproducing sample or reproduce the issue in the provided sample.
3. Screen recorded video of issue with issue replicating steps.
This information would help us to validate your reported problem and to provide you the prompt solution needed.
Please let us know, if you need any further assistance.
Regards,
Muthukrishnan K
Marked as answer
RT
Rolando Tonin
July 22, 2020 12:08 PM UTC
hy Muthukrishnan
Thanks a lot for your suggestion. My mistake was i didn't pass an array to AddNodes as first parameter, but only the new node element. Now it work as expected.
Regards
Rolando
SP
Sowmiya Padmanaban
Syncfusion Team
July 23, 2020 04:17 AM UTC
Hi Rolando,
Most Welcome. We are happy to hear that your problem has been resolved. Please contact us, if you need any help from us.
Regards,
Sowmiya.P
SIGN IN To post a reply.
- 3 Replies
- 3 Participants
- Marked answer
-
RT Rolando Tonin
- Jul 17, 2020 09:02 AM UTC
- Jul 23, 2020 04:17 AM UTC