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"

        });


    }

}







1 Reply

SM Shalini Maragathavel Syncfusion Team August 31, 2021 01:47 PM UTC

Hi Ian, 
 
Greetings from Syncfusion support.  
 
We have validated your reported issue with TreeView component and considered the reported scenario “EnablePersistence property is not working properly in TreeView” as a bug from our end. The fix for this issue will be included in first weekly patch release after Volume 3 release which is expected to be rolled out by the end of September 2021.    

You can track the status of your reported problem through the below portal link. 
  
Feedback: https://www.syncfusion.com/feedback/28335/enablepersistence-property-is-not-working-properly-in-treeview

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
 

Please get back to us if you need further assistance.

Regards,
Shalini M. 


Loader.
Up arrow icon