Custom aggregate in ASP.NET MVC Tree Grid Component

21 Dec 20222 minutes to read

To calculate the aggregate value with your own aggregate functions, use the custom aggregate option. To use custom aggregation, specify the Type as Custom, and provide the custom aggregate function in the CustomAggregate property.

        .Aggregates(agg =>
            agg.Columns(new List<Syncfusion.EJ2.TreeGrid.TreeGridAggregateColumn>() {
                new Syncfusion.EJ2.TreeGrid.TreeGridAggregateColumn() {
                    Type = "Custom", CustomAggregate = "customAggregateFn",
                    FooterTemplate = "Count of Frozen seafood : ${Custom}" , ColumnName = "category"
        .Columns(col =>
          col.Field("units").HeaderText("Total Units").Width(195).Add();
          col.Field("unitPrice").HeaderText("Unit Price($)").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Width(130).Add();


    function customAggregateFn(data) {
        var sampleData = ej.base.getValue('result', data);
        var countLength; countLength = 0;
        sampleData.filter(function (item) {
            var data = ej.base.getValue('category', item);
            if (data === 'Frozen seafood') {
        return countLength;
public IActionResult Index()
    ViewBag.datasource = TreeSummaryData.GetData();
    return View();


To access the custom aggregate value inside the template, use the key as Custom.

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