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. Image for the cookie policy date

TreeGrid WebApiAdaptor

I am trying to implement treegrid with the WebApiAdaptor, I am looking at your example here: https://ej2.syncfusion.com/aspnetcore/TreeGrid/RemoteData#/material.
As I can see you have SelfReferenceData controller to handle the treegrid (url="https://ej2services.syncfusion.com/production/web-services/api/SelfReferenceData").
Can you please send me code for the SelfReferenceData controller because I need to know how this example works.
Thank you in advance!

3 Replies

VN Vignesh Natarajan Syncfusion Team March 11, 2019 06:43 AM

Hi Elena, 
Thanks for contacting Syncfusion support. 
Query : Can you please send me code for the SelfReferenceData controller because I need to know how this example works. 
According to your query we understand that you need to know how to handle the data in the server side for WebAPI service in EJ2 Treegrid. We have achieved your requirement using WebAPI Adaptor of EJS TreeGrid. Please refer the below code example for the same. 
<ejs-treegrid id="TreeGrid" hasChildMapping="isParent" idMapping="taskID" parentIdMapping="parentItem" treeColumnIndex="1" allowPaging="true"> 
        <e-data-manager url="/api/SelfReference" adaptor="WebApiAdaptor" crossDomain="true"></e-data-manager> 
            <e-treegrid-column field="taskID" headerText="Task ID" textAlign="Right" width="120"></e-treegrid-column> 
            <e-treegrid-column field="taskName" headerText="Task Name" width="150"></e-treegrid-column> 
            <e-treegrid-column field="startDate" headerText=" Start Date" textAlign="Right" format="yMd" type="date" width="120"></e-treegrid-column> 
            <e-treegrid-column field="endDate" headerText=" End Date" textAlign="Right" format="yMd" type="date" width="120"></e-treegrid-column> 
            <e-treegrid-column field="duration" headerText="Duration" textAlign="Right" width="110"></e-treegrid-column> 
            <e-treegrid-column field="progress" headerText="Progress" textAlign="Right" width="110"></e-treegrid-column> 
    public class SelfReferenceController : ControllerBase 
        // GET: api/SelfReference 
        public object Get() 
            var queryString = Request.Query; 
            if (SelfReferenceData.tree.Count == 0) 
            if (queryString.Keys.Contains("$filter") &&   // this is used to handle the fiter query to send  
!queryString.Keys.Contains("$inlinecount"))                                                                     the child records when a parent record is expanded 
                StringValues filter; 
                queryString.TryGetValue("$filter", out filter); 
                int fltr = Int32.Parse(filter[0].ToString().Split("eq")[1]); 
                IQueryable<SelfReferenceData> data1 = SelfReferenceData.tree.Where(f => f.ParentItem == fltr).AsQueryable(); 
                return data1.ToList(); 
            List<SelfReferenceData> data = SelfReferenceData.tree.ToList(); 
            if (queryString.Keys.Contains("$select"))    // select query is used to fetch the parent records if                 
            {                                  hasChildMapping is not specified. 
                data = (from ord in SelfReferenceData.tree 
                        select new SelfReferenceData 
                            ParentItem = ord.ParentItem 
                return data; 
            data = data.Where(p => p.ParentItem == null).ToList(); 
            int count = data.Count; 
            if (queryString.Keys.Contains("$inlinecount")) 
                StringValues Skip; 
                StringValues Take; 
                int skip = (queryString.TryGetValue("$skip", out Skip)) ? Convert.ToInt32(Skip[0]) : 0; 
                int top = (queryString.TryGetValue("$top", out Take)) ? Convert.ToInt32(Take[0]) : data.Count(); 
                return new { result = data.Skip(skip).Take(top), count = count }; 
                return data; 
Refer our online documentation for your reference 
Please get back to us if you have further queries. 
Vignesh Natarajan. 

EP Elena Popova March 13, 2019 04:21 AM

Thank you for the information provided!

VN Vignesh Natarajan Syncfusion Team March 13, 2019 10:57 PM

Hi Elena, 

Thanks for the update. 

Please get back to us if you need further assistance on this.  

Vignesh Natarajan. 

Live Chat Icon For mobile
Up arrow icon