Footer Aggregate in ASP.NET CORE Tree Grid Component

21 Dec 20223 minutes to read

Footer aggregate value is calculated for all the rows, and it is displayed in the footer cells. Use the footerTemplate property of e-treegrid-aggregate-column tag helper to render the aggregate value in footer cells.

<ejs-treegrid id="TreeGrid" dataSource="@ViewBag.datasource" height="260" childMapping="Children" treeColumnIndex="1">
    <e-treegrid-aggregates>
        <e-treegrid-aggregate showChildSummary="false">
            <e-treegrid-aggregate-columns>
                <e-treegrid-aggregate-column field="Approved" type="TrueCount" columnName="Approved" footerTemplate="Approved: ${TrueCount}"></e-treegrid-aggregate-column>
            </e-treegrid-aggregate-columns>
        </e-treegrid-aggregate>
    </e-treegrid-aggregates>
    <e-treegrid-columns>
        <e-treegrid-column field="TaskId" headerText="Task ID" textAlign="Right" width="80"></e-treegrid-column>
        <e-treegrid-column field="TaskName" headerText="Task Name" width="200"></e-treegrid-column>
        <e-treegrid-column field="StartDate" headerText=" Start Date" textAlign="Right" format="yMd" type="date" width="100"></e-treegrid-column>
        <e-treegrid-column field="Approved" headerText="Approved" type="boolean" textAlign="Center" displayAsCheckBox="true" width="100"></e-treegrid-column>
    </e-treegrid-columns>
</ejs-treegrid>
public IActionResult Index()
{
    ViewBag.datasource = TreeSummaryData.GetData();
    return View();
}

NOTE

The aggregate values must be accessed inside the template using their corresponding type name.

How to format aggregate value

You can format the aggregate value result by using the format property of e-treegrid-aggregate-column tag helper.

<ejs-treegrid id="TreeGrid" dataSource="@ViewBag.datasource" height="260" childMapping="subTasks" treeColumnIndex="1">
    <e-treegrid-aggregates>
        <e-treegrid-aggregate>
            <e-treegrid-aggregate-columns>
                <e-treegrid-aggregate-column  field="price" columnName = "price" type="Sum" format="C2" footerTemplate="Total: ${Sum}"></e-treegrid-aggregate-column>
            </e-treegrid-aggregate-columns>
        </e-treegrid-aggregate>
    </e-treegrid-aggregates>
    <e-treegrid-columns>
        <e-treegrid-column field="category" headerText="Category" width="130"></e-treegrid-column>
        <e-treegrid-column field="units" headerText="Total Units" textAlign="Right" width="195"></e-treegrid-column>
        <e-treegrid-column field="unitPrice" headerText="Unit Price($)" textAlign="Right" width="130"></e-treegrid-column>
        <e-treegrid-column field="price" headerText="Price($)" format="C2"  textAlign="Right" width="125"></e-treegrid-column>
  </e-treegrid-columns>
</ejs-treegrid>
public IActionResult Index()
{
    ViewBag.datasource = TreeSummaryData.GetData();
    return View();
}

NOTE

You can refer to our ASP.NET Core Tree Grid feature tour page for its groundbreaking feature representations. You can also explore our ASP.NET Core Tree Grid example ASP.NET Core Tree Grid example to knows how to present and manipulate data.