EnablePersistence is not working on screen refresh or Navigation.. 19.2.57
Good afternoon,
I cannot get a Treeview to persist the state of the expanded nodes on either screen refresh or navigation. Once the Tree has loaded and node(s) expanded, refreshing the page or navigating to another page and back again returns the tree to its original load state where all nodes are fully collapsed.
Can you please advise on if there is anything i am doing wrong or if there is a setting missing based on the example code I have supplied below.
Thank you.
// Example code that does not persist nodes in an expanded state
@page "/"
@using Syncfusion.Blazor.Navigations
<SfTreeView TValue="MailItem" ID="tree" EnablePersistence="true">
<TreeViewFieldsSettings TValue="MailItem" Id="Id" DataSource="@MyFolder" Text="FolderName" ParentID="ParentId" HasChildren="HasSubFolders" Expanded="Expanded" ></TreeViewFieldsSettings>
</SfTreeView>
@code{
public class MailItem
{
public string Id { get; set; }
public string ParentId { get; set; }
public string FolderName { get; set; }
public bool Expanded { get; set; }
public bool HasSubFolders { get; set; }
}
List<MailItem> MyFolder = new List<MailItem>();
protected override void OnInitialized()
{
base.OnInitialized();
MyFolder.Add(new MailItem
{
Id = "1",
FolderName = "Inbox",
HasSubFolders = true,
});
MyFolder.Add(new MailItem
{
Id = "2",
ParentId = "1",
HasSubFolders = true,
FolderName = "Categories"
});
MyFolder.Add(new MailItem
{
Id = "3",
ParentId = "2",
FolderName = "Primary"
});
MyFolder.Add(new MailItem
{
Id = "4",
ParentId = "2",
FolderName = "Social"
});
MyFolder.Add(new MailItem
{
Id = "5",
ParentId = "2",
FolderName = "Promotions"
});
MyFolder.Add(new MailItem
{
Id = "6",
FolderName = "Others",
HasSubFolders = true,
Expanded = false
});
MyFolder.Add(new MailItem
{
Id = "7",
ParentId = "6",
FolderName = "Sent Items"
});
MyFolder.Add(new MailItem
{
Id = "8",
ParentId = "6",
FolderName = "Delete Items"
});
MyFolder.Add(new MailItem
{
Id = "9",
ParentId = "6",
FolderName = "Drafts"
});
MyFolder.Add(new MailItem
{
Id = "10",
ParentId = "6",
FolderName = "Archive"
});
}
}
You can track the status of your reported problem through the below portal link.
Until then, we suggest you to use the below workaround solution(hierarchical data).
|
<SfTreeView TValue="MailItem" EnablePersistence="true">
<TreeViewFieldsSettings TValue="MailItem" DataSource="@MyFolder" Expanded="Expanded"></TreeViewFieldsSettings>
</SfTreeView>
@code{
List<MailItem> MyFolder = new List<MailItem>();
protected override void OnInitialized()
{
base.OnInitialized();
List<MailItem> Folder1 = new List<MailItem>();
MyFolder.Add(new MailItem
{
Id = "01",
FolderName = "Inbox",
SubFolders = Folder1
});
List<MailItem> Folder2 = new List<MailItem>();
Folder1.Add(new MailItem
{
Id = "01-01",
FolderName = "Categories",
SubFolders = Folder2
});
List<MailItem> Folder3 = new List<MailItem>();
MyFolder.Add(new MailItem
{
Id = "02",
FolderName = "Others",
Expanded = true,
SubFolders = Folder3
});
Folder3.Add(new MailItem
{
Id = "02-01",
FolderName = "Sent Items"
});
Folder3.Add(new MailItem
{
Id = "02-02",
FolderName = "Delete Items"
});
}
} |
Please find the below sample for your reference
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/TreeView-448129783206827312.zip
Please get back to us if you need further assistance.
Regards,
Shalini M.
- 1 Reply
- 2 Participants
-
IW Ian Wilson
- Aug 30, 2021 02:38 PM UTC
- Aug 31, 2021 01:47 PM UTC