We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to know the parent?

Thread ID:

Created:

Updated:

Platform:

Replies:

145980 Jul 16,2019 02:33 PM UTC Jul 18,2019 09:06 PM UTC Blazor 4
loading
Tags: TreeView
MikeR
Asked On July 16, 2019 02:33 PM UTC

We are using the EjsDataManager with an URL to a web service. We get into the web service but we need to know which tree node we are
to provide the children for. How do we get at this information? We now return children and they get inserted but as we do not know where the children 
will be inserted the tree gets very big. We need to know the ID of the parent which we provide children for, how?



Kanagambigai Murugan [Syncfusion]
Replied On July 17, 2019 12:54 PM UTC

Hi Mikael, 
  
Greetings from Syncfusion. 
  
Query: We get into the web service but we need to know which tree node we are to provide the children for. How do we get at this information? 
  
Based on your information, we have prepared a simple sample for rendering Treeview with URL adaptor. If you want to expand a particular node at initial time itself, you need to set the expanded property as true in the dataSource. It will automatically fetch the child data at rendering time. And also, you can get the requested ParentID using the below code snippet. 
  
// Server side 
  List<loadondemand> treeData = GetTreeData(); 
            IEnumerable<loadondemand> results; 
            if (dm.Where == null) 
            { 
                //return the first level nodes 
                results = treeData.Where(item => item.pid == null); 
            } 
            else 
            { 
                //return the nodes which has pid as we request 
                results = treeData.Where(s => s.pid == Convert.ToInt32(dm.Where[0].value)); 
            } 
            return results; 
        } 
  
// Client side 
<EjsTreeView ID="tree"> 
    <TreeViewFieldsSettings Query="new ej.data.Query()" Id="nodeId" Text="nodeText" HasChildren="hasChild" ParentID="pid" Expanded="expanded"> 
        <EjsDataManager Url="/api/Default" Adaptor="Adaptors.UrlAdaptor" CrossDomain="true"></EjsDataManager> 
    </TreeViewFieldsSettings> 
</EjsTreeView> 
  
  
  
Please check the above sample and let us know if you need any further assistance or if we misunderstood your query. 
  
Regards, 
Kanagambigai M. 


MikeR
Replied On July 17, 2019 09:50 PM UTC

Thanks Kanagambigai,

This was a great step forward, I would also like to pass the parent id of the first node that should be loaded/expanded.
I tried this code below, but I cant get hold of the parameter in the controller.
How can I send a parent ID with the first Query(when no tree is available in the client)
<EjsTreeView id="tree">
            <TreeViewFieldsSettings Query= "new ej.data.Query().addParams('ParID', '12345')"  Id="EmployeeID" Text="FirstName" HasChildren="HasChildren" ParentID="ParentID">
                <EjsDataManager url="api/Structure" Adaptor="Adaptors.UrlAdaptor" CrossDomain="true"></EjsDataManager>
                <TreeViewFieldChild Query= "new ej.data.Query()" Id="EmployeeID" Text="FirstName" HasChildren="HasChildren" ParentID="ParentID"  Expanded="expanded">
                    <EjsDataManager url="api/Structure" Adaptor="Adaptors.UrlAdaptor"  CrossDomain="true" ></EjsDataManager>
                </TreeViewFieldChild>
            </TreeViewFieldsSettings>
        </EjsTreeView>

/Mike

Kanagambigai Murugan [Syncfusion]
Replied On July 18, 2019 11:45 AM UTC

Hi Mikael, 
  
Thanks for your update. 
  
Query: How can I send a parent ID with the first Query(when no tree is available in the client) 
  
You can pass the parentID as an additional parameter along with the Query using the addParams method on the client-side. On the server-side, you have to define this additional parameter. Please refer to the following code snippet. 
  
//Client side 
<EjsTreeView ID="tree"> 
        <TreeViewFieldsSettings Query="new ej.data.Query().addParams('ParentID','5')" Id="employeeID" Text="firstName" HasChildren="employeeID"> 
            <EjsDataManager Url="/api/Default" Adaptor="Adaptors.UrlAdaptor" CrossDomain="true"></EjsDataManager> 
            <TreeViewFieldChild Id="orderID" Text="customerID"  ParentID="employeeID" Expanded="expanded"> 
                <EjsDataManager Url="api/Child" Adaptor="Adaptors.UrlAdaptor" CrossDomain="true"></EjsDataManager> 
            </TreeViewFieldChild> 
        </TreeViewFieldsSettings> 
    </EjsTreeView> 
 
// server side 
// Extends the DataManager 
public class CustomClass : DataManagerRequest 
{ 
    public CustomParams Params { get; set; } 
} 
// Definition for the additional parameter 
public class CustomParams 
{ 
    public int ParentID { get; set; } 
}  
[HttpPost] 
        public object Post([FromBody]CustomClass dm) 
        { 
            BindDataSource(); 
            var data = order.AsQueryable(); 
            var count = order.Count; 
            var queryString = dm.Params.ParentID; 
            if (dm.Where == null) 
            { 
                int top = Convert.ToInt32(queryString); 
               results = data.Where(s => s.EmployeeID == top); 
            } 
            return results; 
        } 
 
  
In the above sample,  we have passed the id as ‘5’, which will get loaded first. 
   
 
  
Kindly check the above sample and get back to us if you need any further assistance. 
  
Regards, 
Kanagambigai M. 



MikeR
Replied On July 18, 2019 09:06 PM UTC

Thanks Kanagambigai,
This works great!

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon