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

Hierarchy Grid ej2

Thread ID:

Created:

Updated:

Platform:

Replies:

143691 Apr 1,2019 11:09 AM UTC Apr 12,2019 03:51 AM UTC ASP.NET Core - EJ 2 7
loading
Tags: DataGrid
Yoab Youssoufou
Asked On April 1, 2019 11:09 AM UTC

Hello,
 I am converting a project from ej1 to ej2 and am presently doing the new way of handling hierarchy grids with child grid. So far so good below is my code:

@{

    var ChildGrid1 = new Syncfusion.EJ2.Grids.Grid()
    {
        DataSource = @sp.SPGetSubBids(3, config.GetConnectionString("HectareConnection")),
        QueryString = "BidId",
        Columns = new List<Syncfusion.EJ2.Grids.GridColumn> {
new Syncfusion.EJ2.Grids.GridColumn(){ Field="Produce", HeaderText="Produce", Width="200" },
new Syncfusion.EJ2.Grids.GridColumn(){ Field="TotalBidQty", HeaderText="Quantity", Width="70",  Format="N0" },
new Syncfusion.EJ2.Grids.GridColumn(){ Field="NumLots", HeaderText="Num Lots", Width="80", Format="N0" },
new Syncfusion.EJ2.Grids.GridColumn(){ Field="QtyPerLot", HeaderText="Qty/Lot", Width="80", Format="N0" },
}

    };
}

=============================================

   <ejs-grid id="PublishedGrid" dataSource="@sp.GetBidsByStatuses(3,config.GetConnectionString("HectareConnection"))" childGrid="ChildGrid1" allowPaging="true" gridLines="Both">
                                <e-grid-pagesettings pageSize="10"></e-grid-pagesettings>
                                <e-grid-editSettings allowAdding="false" allowDeleting="false" allowEditing="false" showDeleteConfirmDialog="true" showConfirmDialog="true"></e-grid-editSettings>
                                <e-grid-textwrapsettings wrapMode="Both"></e-grid-textwrapsettings>

                                <e-grid-columns>
                                    <e-grid-column field="BidId" isIdentity="true" isPrimaryKey="true" width="80" textAlign="Right" visible="true"></e-grid-column>
                                    <e-grid-column field="BidsId" headertext="HReadable"></e-grid-column>
                                    <e-grid-column field="BidDate" headertext="Bid Date"></e-grid-column>
                                    <e-grid-column field="BidClosingDate" headertext="Closing Date"></e-grid-column>
                                </e-grid-columns>
                            </ejs-grid>

This code works without issues. I have 2 problems:
1) is i need to add aggregate functions (sum, total, count etc.. ) in the child grid and 
2) How to add a custom command button in ej1 I could simply add :  <e-column header-text="Participate" width="120" Template="<a rel='nofollow' href='Home/Participate/?Id={{:Id}}' class='modal-link btn-xs btn-success'>Participate</a>" allow-editing="false"></e-column>
how do i do this with the new childgrid syntax

Thanks in advance

Pavithra Subramaniyam [Syncfusion]
Replied On April 2, 2019 12:27 PM UTC

Hi Yoab, 
 
Thanks for contacting Syncfusion support, 
 
Query #1:  is i need to add aggregate functions (sum, total, count etc.. ) in the child grid and  
 
From your query we suspect that you want to add Aggregates for the child grid. If so, you can achieve your requirement by adding the “Aggregates” property in the child grid definition as given below. 
 
[index.cshtml] 
@{ 
    var col = new List<Syncfusion.EJ2.Grids.GridAggregateColumn> { 
              new Syncfusion.EJ2.Grids.GridAggregateColumn(){ Field = "FirstName", Format = "C2", Type = "count", FooterTemplate = "Count: ${count}" } 
}; 
} 
@{ 
            var ChildGrid1 = new Syncfusion.EJ2.Grids.Grid() 
            { 
                DataSource = ViewBag.empData, 
                QueryString = "EmployeeID", 
                Aggregates = new List<Syncfusion.EJ2.Grids.GridAggregate> { 
            new Syncfusion.EJ2.Grids.GridAggregate() {Columns =col} }, 
               .  .  . 
            }; 
        } 
 
============================================= 
 
<ejs-grid id="PublishedGrid" dataSource="ViewBag.data" childGrid="ChildGrid1" allowPaging="true" gridLines="Both"> 
 
    <e-grid-columns> 
        <e-grid-column field="OrderID" isIdentity="true" isPrimaryKey="true" width="80" textAlign="Right" visible="true"></e-grid-column> 
        .  .  . 
    </e-grid-columns> 
</ejs-grid> 
 
Query #2: How to add a custom command button 
 
You can add the custom button in the columns by simply using the “Template” property as you do in EJ1. The only difference is We have expression evolution as like ES6 expression string literals ( ex: ${name} ). Please refer to the below code example and sample link for more information. 
 
[index.cshtml] 
@{ 
            var ChildGrid1 = new Syncfusion.EJ2.Grids.Grid() 
            { 
                DataSource = ViewBag.empData, 
                QueryString = "EmployeeID", 
   Columns = new List<Syncfusion.EJ2.Grids.GridColumn> { 
           new Syncfusion.EJ2.Grids.GridColumn(){ Field="FirstName", HeaderText="Produce", Width="200" }, 
           new Syncfusion.EJ2.Grids.GridColumn(){ Field="EmployeeID", Template="<a rel='nofollow' rel='nofollow' href='Home/Participate/?Id=${EmployeeID}' class='modal-link btn-xs btn-success'>Participate</a>", HeaderText="Quantity", Width="70",  Format="N0" } 
}               .  .  . 
            }; 
        } 
 
============================================= 
 
<ejs-grid id="PublishedGrid" dataSource="ViewBag.data" childGrid="ChildGrid1" allowPaging="true" gridLines="Both"> 
 
    <e-grid-columns> 
        <e-grid-column field="OrderID" isIdentity="true" isPrimaryKey="true" width="80" textAlign="Right" visible="true"></e-grid-column> 
        .  .  . 
    </e-grid-columns> 
</ejs-grid> 
 
 
 
Please get back to us, if you have any concern. 
 
Regards, 
Pavithra S. 


Yoab Youssoufou
Replied On April 3, 2019 12:37 AM UTC

Thank you very much, problem solved.

Pavithra Subramaniyam [Syncfusion]
Replied On April 3, 2019 04:43 AM UTC

Hi Yoab,  

Thanks for your update. 

We are happy to hear that the provided solution helped you.  

Please contact us if you need any further assistance. As always, we will be happy to assist you.  

Regards,  
Pavithra S. 
 


Yoab Youssoufou
Replied On April 9, 2019 07:58 PM UTC

Hello again,
Please how with this same example can I implement CRUD in the child grid? and also with a field having a foreign key 
normally I handle it like this:

  
 
headertext="Produce Group" 
foreignkeyfield="Id" 
allowediting="true" 
foreignkeyvalue="Name" 
width="165" 
  datasource="@gen.GetLkProduceGroups()">


How can I do this in the Child Grid.

Thanks

Hariharan J V [Syncfusion]
Replied On April 11, 2019 04:42 PM UTC

Hi Yoab, 

Thanks for your update. 

As per your suggestion we have created a sample with foreign key column and editing feature in child Grid. Please refer the below code example and sample for more information. 

 
@{ 
            var ChildGrid1 = new Syncfusion.EJ2.Grids.Grid() 
            { 
                DataSource = ViewBag.empData, 
                QueryString = "EmployeeID", 
                EditSettings = new Syncfusion.EJ2.Grids.GridEditSettings() { AllowAdding = true, AllowEditing = true, AllowDeleting = true }, 
                Toolbar = new List<string>() { "Add", "Edit", "Delete", "Update", "Delete" }, 
                Aggregates = new List<Syncfusion.EJ2.Grids.GridAggregate> { 
            new Syncfusion.EJ2.Grids.GridAggregate() {Columns =col} }, 
                Columns = new List<Syncfusion.EJ2.Grids.GridColumn> { 
new Syncfusion.EJ2.Grids.GridColumn(){ Field="orderid", HeaderText="ID", IsPrimaryKey=true, Width="200" }, 
new Syncfusion.EJ2.Grids.GridColumn(){ Field="id", ForeignKeyField="EmployeeID1", ForeignKeyValue="FullName", DataSource= ViewBag.empData1, HeaderText="Full Name", Width="200" }, 
} 
 
            }; 
        } 
 
============================================= 
 
<ejs-grid id="PublishedGrid" dataSource="ViewBag.data" childGrid="ChildGrid1" allowPaging="true" gridLines="Both"> 
    <e-grid-pagesettings pageSize="10"></e-grid-pagesettings> 
    <e-grid-editSettings allowAdding="false" allowDeleting="false" allowEditing="false" showDeleteConfirmDialog="true" showConfirmDialog="true"></e-grid-editSettings> 
    <e-grid-textwrapsettings wrapMode="Both"></e-grid-textwrapsettings> 
 
    <e-grid-columns> 
        <e-grid-column field="OrderID" isIdentity="true" isPrimaryKey="true" width="180" textAlign="Right" visible="true"></e-grid-column> 
        <e-grid-column field="EmployeeID" headertext="HReadable" width="150"></e-grid-column> 
    </e-grid-columns> 
</ejs-grid> 
 


Regards, 
Hariharan 


Yoab Youssoufou
Replied On April 11, 2019 05:25 PM UTC

Perfect! Thank you

Hariharan J V [Syncfusion]
Replied On April 12, 2019 03:51 AM UTC

Hi Yoab, 
 
Thanks for your update.  
  
We are happy to hear that the provided solution helped you.   
  
Please contact us if you need any further assistance. As always, we will be happy to assist you.   
  
Regards, 
Hariharan 


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