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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

TreeGrid WebApiAdaptor

Thread ID:

Created:

Updated:

Platform:

Replies:

143195 Mar 8,2019 11:54 AM UTC Mar 14,2019 03:57 AM UTC ASP.NET Core - EJ 2 3
loading
Tags: Tree Grid
Elena Popova
Asked On March 8, 2019 11:54 AM UTC

Hi,
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!
Elena


Vignesh Natarajan [Syncfusion]
Replied On March 11, 2019 11:43 AM UTC

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. 
 
[index.cshtml] 
<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-columns> 
            <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> 
        </e-treegrid-columns> 
    </ejs-treegrid> 
 
[selfreferencecontroller.cs] 
 
[Route("api/[controller]")] 
    [ApiController] 
    public class SelfReferenceController : ControllerBase 
    { 
 
        // GET: api/SelfReference 
        [HttpGet] 
        public object Get() 
        { 
            var queryString = Request.Query; 
            if (SelfReferenceData.tree.Count == 0) 
                SelfReferenceData.GetTree(); 
            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 
                        } 
                        ).ToList(); 
                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 }; 
            } 
            else 
            { 
                return data; 
            } 
        } 
 
Refer our online documentation for your reference 
 
 
Please get back to us if you have further queries. 
 
Regards, 
Vignesh Natarajan. 
 


Elena Popova
Replied On March 13, 2019 09:21 AM UTC

Thank you for the information provided!

Vignesh Natarajan [Syncfusion]
Replied On March 14, 2019 03:57 AM UTC

Hi Elena, 

Thanks for the update. 

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

Regards, 
Vignesh Natarajan. 


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

;