how to expand in grid?

hello, syncfusion teams.


i want to expand rows in tree grid.

i generated the code as below. how to expand in tree grid?


thank you


<ejs-treegrid id="DetailTreeGrid" cellEdit="DetailTreeGridCellEdit" gridLines="Both" rowHeight="30" height="500px"
                  treeColumnIndex="0" idMapping="DNO" hasChildMapping="IS_PARENT" parentIdMapping='P_DNO'>
        <e-data-manager url="/DV/[email protected]&EqCode=0" crudUrl="/DV/DS_DETAIL_CRUD" adaptor="UrlAdaptor"></e-data-manager>
        <e-treegrid-columns>
            <e-treegrid-column field="DNO" headerText="NO" width="80" defaultValue="@empty" headerTextAlign="Center" textAlign="Left" isPrimaryKey="true"></e-treegrid-column>
            <e-treegrid-column field="TITLE" headerText="TITLE" width="300" defaultValue="@empty" headerTextAlign="Center" textAlign="Left"></e-treegrid-column>
            <e-treegrid-column field="REQ" headerText="PURCHASER'S REQUIREMENT" defaultValue="@empty" headerTextAlign="Center" textAlign="Center"></e-treegrid-column>


            <e-treegrid-column field="POPUP_USE" headerText="" width="80" template="#reqChange" defaultValue="@empty" headerTextAlign="Center" textAlign="Center"></e-treegrid-column>
            <e-treegrid-column field="DEFAULT_VALUE" visible="false"></e-treegrid-column>


            <e-treegrid-column field="REPLY" headerText="VENDOR REPLY / PROPOSAL" defaultValue="@empty" headerTextAlign="Center" textAlign="Center"></e-treegrid-column>
        </e-treegrid-columns>
    </ejs-treegrid>

3 Replies

FS Farveen Sulthana Thameeztheen Basha Syncfusion Team February 14, 2022 03:21 PM UTC

Hi TaeWook, 

Query#:- i want to expand rows in tree grid. 
 
From your provided code example, you have used RemoteData Binding for TreeGrid. While using remoteData to TreeGrid, by default TreeGrid parent rows has been rendered with collapsed state at initial load. On expanding the root node, the child nodes will be loaded from the remote server. 

When a root node is expanded, its child nodes are rendered and are cached locally, such that on consecutive expand/collapse actions on root node, the child nodes are loaded from the cache instead from the remote server. 
Refer to the documentation link:- 
 
Instead if you want to expand the rows at Initial Load while using Remote Data , you can use loadChildOnDemand property of TreeGrid. When loadChildOnDemand is enabled parent records are rendered in expanded state. Also we need to handle the child records on server end as like given below:- 
 
Refer to the code below:- 
Index.cshtml 

<ejs-treegrid id="TreeGrid" idMapping="TaskID" parentIdMapping="ParentValue" hasChildMapping="isParent" treeColumnIndex="1" allowPaging="true" loadChildOnDemand="true"> 
            <e-treegrid-pagesettings pageSize="7"></e-treegrid-pagesettings>   
            <e-data-manager url="/Home/DataSource" adaptor="UrlAdaptor"></e-data-manager> 
            <e-treegrid-columns> 
                <e-treegrid-column field="TaskID" headerText="ID" isPrimaryKey="true" textAlign="Left" width="40"></e-treegrid-column> 
                .   .    . 
> 
            </e-treegrid-columns> 
 
</ejs-treegrid> 

Controller:- 

public IActionResult DataSource([FromBody] DataManagerRequest dm) 
        { 
            IEnumerable DataSource = TreeData.GetTree(); 
            DataOperations operation = new DataOperations(); 
            if (dm.Where != null && dm.Where.Count > 0) //filtering 
            { 
                DataSource = operation.PerformFiltering(DataSource, dm.Where, "and"); 
            } 
            if (dm.Search != null && dm.Search.Count > 0) 
            { 
                DataSource = operation.PerformSearching(DataSource, dm.Search); 
            } 
            if (dm.Sorted != null && dm.Sorted.Count > 0) 
            { 
                DataSource = operation.PerformSorting(DataSource, dm.Sorted); 
            } 
            var count = TreeData.GetTree().Count(); 
            if (dm.Skip != 0) 
            { 
                DataSource = operation.PerformSkip(DataSource, dm.Skip);   //Paging 
            } 
            if (dm.Take != 0) 
            { 
                DataSource = operation.PerformTake(DataSource, dm.Take); 
            } 
 
            if (dm.Where != null) 
            { 
                DataSource = CollectChildRecords(DataSource, dm); 
            } 
            return dm.RequiresCounts ? Json(new { result = DataSource, count = count }) : Json(DataSource); 
 
        } 
 
        public IEnumerable CollectChildRecords(IEnumerable datasource, [FromBody] DataManagerRequest dm) 
        { 
            DataOperations operation = new DataOperations();       // handle child records at server end 
            IEnumerable DataSource = TreeData.tree; 
            string IdMapping = "TaskID"; 
            int[] TaskIds = new int[0]; 
            foreach (var rec in datasource) 
            { 
                int taskid = (int)rec.GetType().GetProperty(IdMapping).GetValue(rec); 
                TaskIds = TaskIds.Concat(new int[] { taskid }).ToArray(); 
            } 
            IEnumerable ChildRecords = null; 
            foreach (int id in TaskIds) 
            { 
                dm.Where[0].value = id; 
                IEnumerable records = operation.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator); 
                ChildRecords = ChildRecords == null || (ChildRecords.AsQueryable().Count() == 0) ? records : ((IEnumerable<object>)ChildRecords).Concat((IEnumerable<object>)records); 
            } 
            if (ChildRecords != null) 
            { 
                ChildRecords = CollectChildRecords(ChildRecords, dm); 
                if (dm.Sorted != null && dm.Sorted.Count > 0) // perform Sorting 
                { 
                    ChildRecords = operation.PerformSorting(ChildRecords, dm.Sorted); 
                } 
                datasource = ((IEnumerable<object>)datasource).Concat((IEnumerable<object>)ChildRecords); 
            } 
            return datasource; 
        } 

Refer to the API Link for more information:- 
 
Screenshot:- 
 

If your requirement is different from above or we misunderstood your query, please get back to us with further details. 

 
Regards, 
Farveen sulthana T 



TK TaeWook Kang replied to Farveen Sulthana Thameeztheen Basha February 15, 2022 09:57 AM UTC

Thanks for your reply.


There is a some error and i can't solve it.


could you please send me the sample code?


> IEnumerable DataSource = TreeData.tree;


Please include the TreeData Class.


thank you




FS Farveen Sulthana Thameeztheen Basha Syncfusion Team February 16, 2022 02:36 PM UTC

Hi TaeWook, 

We have created sample using loadChildOnDemand concept which expand all the parent rows while using Remote Data which can be downloaded from below location. 

Screenshot:- 
 

Please get back to us if you need any further assistance. 

Regards, 
Farveen sulthana T 


Loader.
Up arrow icon