Get the corresponding dataobject (typed toward the correct Data Model) of the currently checked item in TreeView ?
I have the follow :
<SfTreeView @ref="treeViewBuses" TValue="TreeProxyDataModel " ShowCheckBox="true" HtmlAttributes="@htmlAttributeBusTree">
<TreeViewEvents TValue="@(TreeProxyDataModel )" NodeChecked="@onCheckNode"></TreeViewEvents>
<TreeViewFieldsSettings DataSource="@DataProviders.treeData"
Id="id"
ParentID="groupID"
Text="Caption"
Expanded="expanded"
HasChildren="hasChild"
IsChecked="selected">
public async Task onCheckNode( NodeCheckEventArgs o )
{
Console.WriteLine( o.Data.ToArray().ToString() );
}
- How to get the currently checked element from DataProviders.treeData provider in the onCheckNode event ?
SIGN IN To post a reply.
3 Replies
1 reply marked as answer
SP
Sowmiya Padmanaban
Syncfusion Team
June 18, 2020 11:04 AM UTC
Hi Yordon,
We have checked your reported query with TreeView component. We would like to let you know that nodeChecked and nodeChecking events return only the default mapping field of the checked node. In TreeView component, by using its getTreeData method, you can fetch the value defined in the data source of TreeView component to achieve your expected requirement.
If you pass particular node id as argument for getTreeData method, then it will return the corresponding node data. Or else, the method return the entire datasource of TreeView component.
Refer the below code snippet.
|
public async Task nodechecking(NodeCheckEventArgs args)
{
// Particular node id
var data= args.Data[0].Id;
// To fetch the corresponding node from TreeView Datasource
var node_data = await this.tree.GetTreeData(args.Data[0].Id);
} |
Refer the below screenshot.
Refer the sample link below.
To know more about the TreeView component. Refer the below links.
UG Documentation- https://blazor.syncfusion.com/documentation/treeview/data-binding/#self-referential-data
Please let us know, if you need any further assistance.
Regards,
Sowmiya.P
Marked as answer
YO
Yordan
June 18, 2020 02:50 PM UTC
Didn't knew that i have to call it this way, searched like everywhere.
Thank You kindly support.
Thank You kindly support.
SP
Sowmiya Padmanaban
Syncfusion Team
June 19, 2020 06:54 AM UTC
Hi Yordon,
Most Welcome. We are happy to hear that your problem has been resolved. Please contatc us, if you need any help from us.
Regards,
Sowmiya.P
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
- Marked answer
-
YO Yordan
- Jun 17, 2020 05:53 PM UTC
- Jun 19, 2020 06:54 AM UTC