Adding a @ref for a TreeView control, I'm unable to call the .ExpandAllAsync() method after data is bound due to a null reference exception. I've tried the following events: OnInitializedAsync, OnAfterRenderAsync, TreeView.OnCreated, TreeView.DataBound. Where and/or when is the appropriate place to do so, so that the @ref is no longer null? I know the @ref is bound correctly because if I add a button with a click event, the call can be made as the reference is no longer null.
Thanks,
-jv
Hi Jeff,
Greetings from Syncfusion support.
As per the shared details, we have checked the reported issue in Blazor TreeView component. We have prepared a simple sample of TreeView with Created and DataBound event to call ExpandAllAsync method in TreeView and the property works fine with the TreeView reference. We suspect that the issue occurs due to incorrect TreeView reference. We have attached the prepared sample for your reference.
Refer to the below code snippet.
|
[Index.razor]
<SfTreeView TValue="MailItem" @ref="treeObj"> ... <TreeViewEvents TValue="MailItem" Created="Oncreated" DataBound="OndataBound"></TreeViewEvents> </SfTreeView>
@code{ SfTreeView<MailItem> treeObj;
public void Oncreated(ActionEventArgs args) { treeObj.ExpandAllAsync(); } public void OndataBound(DataBoundEventArgs<MailItem> args) { treeObj.ExpandAllAsync(); } |
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/BlazorApp12110415300.zip
Please check the attached sample and get back to us, if you need any further assistance.
Regards,
Sivakumar S
The sample you've attached is not similar enough to what we are trying to achieve. I've attached our sample (watered down) and you can see that nothing is expanded after the initial load.
Thanks,
-Jeff V.
Hi Jeff,
Thanks for the shared sample, we have checked the reported issue with sample attached in your update. We are able to replicate the reported issue from our side with the shared sample. We are currently validating the root cause of the reported issue and will provide an update on or before August 04, 2022.
We appreciate your patience.
Regards,
Sivakumar S
Hi Jeff,
We have validated the reported issue in the Blazor TreeView component and considered it 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 link: 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.
We appreciate your patience.
Regards,
Sivakumar S
Hi Jeff,
Sorry for the inconvenience.
Due to high priority features and bug fixes, we were unable to include the fix as promised. The fix for this issue will be included in our weekly patch release on September 13, 2022. We appreciate your patience.
Regards,
Leo Lavanya Dhanaraj
Hi Jeff,
We deeply regret for the inconvenience.
Due to unforeseen circumstances, we were unable to include the fix as promised. The fix for this issue will be included in our Volume 3 release which is expected to be rolled out at the end of September 2022. We appreciate your patience.
Regards,
Indhumathy L
Hi Jeff,
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() { DataSource = await Http.GetFromJsonAsync<List<Element>>("sample-data/taxonomy-mid.json"); if (DataSource != null) { StateHasChanged(); }
} protected override async Task OnAfterRenderAsync(bool firstRender) { if (!firstRender) { await Control.ExpandAllAsync(); } } } |
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/BlazorTreeViewBug-1275321.zip
Please check the attached sample and get back to us if you need any further assistance.
Regards,
Sivakumar S