Welcome to the Blazor feedback portal. We’re happy you’re here! If you have feedback on how to improve the Blazor, we’d love to hear it!

  • Check out the features or bugs others have reported and vote on your favorites. Feedback will be prioritized based on popularity.
  • If you have feedback that’s not listed yet, submit your own.

Thanks for joining our community and helping improve Syncfusion products!

1
Vote

Hello,

when we update the Syncfusion packages to a newer version than 20.2.0.36 our TreeView doesn't persist the expanded objects anymore, only the selected object seems to be persisted. Here you find the affected code:


Snippet
@using PlatoNG.Blazor.Data
@using PlatoNG.Domain.DTO
@using PlatoNG.Domain.Models
@using PlatoNG.Application.Interfaces
@using Syncfusion.Blazor
@using Syncfusion.Blazor.DropDowns
@using Syncfusion.Blazor.Navigations
@using Syncfusion.Blazor.Inputs
@using Syncfusion.Blazor.TreeGrid
@using Syncfusion.Blazor.Buttons
 
@*@implements IDisposable*@
@inject AppState appState
@inject IPspService pspService
 
@if (filteredPspItems == null)
{
    <div class="spinner-border" role="status">
        <span class="visually-hidden">Laden...</span>
    </div>
}
else
{
    <form onsubmit="@ApplyFilter">
        <div class="row my-2">
            <div class="col-sm-10">
                <SfTextBox ShowClearButton="true" ValueChange="@ApplyFilter" @bind-Value="@pspFilter"></SfTextBox>
            </div>
            <div class="col">
                <SfButton CssClass="w-100" OnClick="@ApplyFilter">Filtern</SfButton>
            </div>
        </div>
    </form>
    <div class="row my-2">
        <SfTreeView ExpandOn="ExpandAction.Click" @ref="@SfPspTreeView" ID="pspTreeView" EnablePersistence="true" TValue="PspTreeItem">
            <TreeViewFieldsSettings TValue="PspTreeItem" Id="Id" DataSource="@filteredPspItems" Text="Name" Expanded="Expanded" HasChildren="HasSubFolders" ParentID="ParentId"></TreeViewFieldsSettings>
        </SfTreeView>
    </div>
 
}
 
@code {
    IEnumerable<PspTreeItem>? pspItems;
    IEnumerable<PspTreeItem>? filteredPspItems;
    SfTreeView<PspTreeItem> SfPspTreeView;
 
    string pspFilter = "";
 
    private IEnumerable<PspTreeItemAddParents(List<PspTreeItemoriginalList<PspTreeItemcurrentList<PspTreeItemparents)
    {
        if (current.Count() > 0)
        {
            var currentParents = original.Where(x => !parents.Any(p => p.Id == x.Id) && current.Any(c => c.ParentId == x.Id)).Distinct().ToList();
            parents.AddRange(currentParents);
            return AddParents(originalcurrentParentsparents);
        }
        return parents.Distinct();
    }
 
    private IEnumerable<PspTreeItemAddChildren(List<PspTreeItemoriginalList<PspTreeItemcurrentList<PspTreeItemchildren)
    {
        if (current.Count() > 0)
        {
            var currentChildren = original.Where(x => current.Any(c => !children.Any(ch => ch.Id == x.Id) && c.Id == x.ParentId)).Distinct().ToList();
            children.AddRange(currentChildren);
            return AddChildren(originalcurrentChildrenchildren);
        }
        return children.Distinct();
    }
 
    public async Task ApplyFilter()
    {
        if (string.IsNullOrEmpty(pspFilter))
        {
            filteredPspItems = pspItems;
        }
        else
        {
            var filteredItems = pspItems.Where(x => x.Name.Contains(pspFilter, StringComparison.InvariantCultureIgnoreCase)).ToList();
            var parents = AddParents(pspItems.ToList(), filteredItemsnew List<PspTreeItem>());
            var children = AddChildren(pspItems.ToList(), filteredItemsnew List<PspTreeItem>());
            filteredItems.AddRange(parents);
            filteredItems.AddRange(children);
            filteredPspItems = filteredItems.DistinctBy(x => x.Id);
        }
        StateHasChanged();
    }
 
    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            pspItems = await appState.GetPsptree();
            filteredPspItems = pspItems;
 
            StateHasChanged();
 
            // This is required to update the treeview with the persisted data.
            // Without doing this, the nodes are not expanded to the previous state
            await Task.Delay(50);
            StateHasChanged();
            await Task.Delay(200);
            StateHasChanged();
            await Task.Delay(1000);
            StateHasChanged();
        }
 
    }
 
    public async Task SetSelectedPspAsync()
    {
        if (SfPspTreeView.SelectedNodes != null)
        {
            await appState.SetSelectedPspAsync(SfPspTreeView.SelectedNodes.FirstOrDefault());
        }
    }
}