Clear All Items From TreeView and Rebind
Hi There,
I would to replace the data in an SFTreeView completely. Not add or remove a single node, but all the nodes.
Then I would like to rebind the data against a different data source (of the same type of items).
How do I do this?
Thanks
SIGN IN To post a reply.
3 Replies
1 reply marked as answer
MK
Muthukrishnan Kandasamy
Syncfusion Team
August 17, 2020 06:20 AM UTC
Hi Joseph,
Thanks for contacting Syncfusion support.
We have validated your requirement in Syncfusion Blazor TreeView component. We can rebind the TreeView component with new set of data source dynamically. We have prepared a sample to meet your requirement. In this sample, we have updated the new data source to TreeView component. Please refer to the below link for the sample.
|
Description |
Link |
|
Getting started |
|
|
CRUD operation |
|
|
API reference |
|
|
Live demo |
Please let us know, if you need any further assistance.
Regards,
Muthukrishnan K
JT
Joseph Tan
August 19, 2020 02:22 AM UTC
Hi
Thanks - so funny - I tried all sorts of combinations of AddNodes and RemoveNodes,but all one has to do is reassign the DataSource.
Cheers
SP
Sowmiya Padmanaban
Syncfusion Team
August 19, 2020 09:39 AM UTC
Hi Joseph Tan,
We would like to let you know that AddNodes and RemoveNodes are working fine in TreeView component. If you need to add/remove a new node to the existing datasource you can use the AddNodes and RemoveNodes method. But, when changing the complete datasource, you can reassign the value to the Datasource property.
Refer to the below code snippet.
|
<SfButton OnClick="Change" Content="Change"></SfButton>
<SfButton OnClick="Add" Content="Add node"></SfButton>
<SfButton OnClick="Remove" Content="Remove Node"></SfButton>
<SfTreeView TValue="MailItem" @ref="tree">
<TreeViewFieldsSettings TValue="MailItem" Id="Id" DataSource="@MyFolder" Text="Name" ParentID="ParentId" HasChildren="HasChild" Expanded="Expanded"></TreeViewFieldsSettings>
</SfTreeView>
public void Add()
{
List<MailItem> Child = new List<MailItem>();
Child.Add(new MailItem
{
Id = "45",
Name = "Music"
});
Child.Add(new MailItem
{
Id = "10",
Name = "Pictures",
});
this.tree.AddNodes(Child, null);
}
public void Remove()
{
this.tree.RemoveNodes(new string[] { "45" });
} |
Refer to the sample link below.
Please let us know, if you need any further assistance.
Regards,
Sowmiya.P
Marked as answer
SIGN IN To post a reply.
- 3 Replies
- 3 Participants
- Marked answer
-
JT Joseph Tan
- Aug 15, 2020 10:22 AM UTC
- Aug 19, 2020 09:39 AM UTC