Expand treeview node when page is loaded

Hi,

I have a problem with programmatically expanding nodes by calling ExpandAll method when a list of nodes is populated from a HTTP request.  

I have found a similar issue in thread https://www.syncfusion.com/forums/156397/expand-to-node-when-page-is-loaded. However, if I try to modify the example from the thread to simulate asynchronous HTTP request, the example stops working and nodes do not expand.  If I comment out the Task.Delay call it starts working again.

Is there anything I can do on my side or is this a bug in Syncfusion library?

Best regards,

David


Attachment: TreeExpanded1303825494_9037c658.zip

2 Replies 1 reply marked as answer

PM Prasanth Madhaiyan Syncfusion Team August 5, 2022 12:16 PM UTC

Hi Ddrapela,


Greetings from Syncfusion support.


We have validated the reported query, and this has already been considered as a bug at our end. The fix for this issue will be included in our weekly patch release on August 30, 2022. You can track the status of the issue fix using the following feedback link.


Feedback: https://www.syncfusion.com/feedback/36839/expandallasync-is-not-working-with-dynamic-data-in-the-blazor-wasm-treeview


Disclaimer: Inclusion of this solution in the weekly release may change due to other factors including but not limited to QA checks and works reprioritization.


Regards,

Prasanth Madhaiyan.


Marked as answer

SS Sivakumar ShunmugaSundaram Syncfusion Team September 20, 2022 03:48 PM UTC

Hi Ddrapela,


Thanks for your patience.


On our further validation, the reported issue occurs due to expanding the TreeView node using the ExpandAllAsync method in the TreeView DataBound event. We would like to let you know that the Treeview component is ready after the DataBound event, once we tried to expand the node in that event, it executes before the component renders and that is why the nodes are not expanded at the initial render. To overcome the issue, we suggest you expand the TreeView nodes in the Blazor OnAfterRenderAsync life cycle. Which is triggered after the component is ready to render in the UI. We have attached the prepared sample for your reference.


Refer to the below code snippet.

[Index.razor],

 

 

@code{

...

    protected override async Task OnInitializedAsync()

    {

        await base.OnInitializedAsync();

        await Task.Delay(100);//simulate http request

...

    protected override async Task OnAfterRenderAsync(bool firstRender)

    {

       if (!firstRender)

        {

        await treeView.ExpandAllAsync();

       

        }

    }

   

}


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/TreeExpanded1303825494-762871418.zip


Please check the attached sample and get back to us if you need any further assistance.


Regards,

Sivakumar S


Loader.
Up arrow icon