Group and Caption Aggregate
21 Dec 20221 minute to read
Group and caption aggregate values are calculated from the current group items. If GroupFooterTemplate
is provided, the aggregate values are displayed in the group footer cells; and if GroupCaptionTemplate
is provided, aggregate values are displayed in the group caption cells.
@Html.EJS().Grid("GroupCaption").DataSource((IEnumerable<object>)ViewBag.DataSource).Columns(col =>
{
col.Field("CustomerID").HeaderText("Customer Name").Width("150").Add();
col.Field("Freight").HeaderText("Freight").Width("160").Format("C2").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("OrderDate").HeaderText("Order Date").Width("130").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Format("yMd").Add();
col.Field("ShipCountry").HeaderText("Ship Country").Width("140").Add();
}).AllowPaging().PageSettings(page => { page.PageCount(5); }).AllowGrouping().GroupSettings(new Syncfusion.EJ2.Grids.GridGroupSettings() { Columns = new string[] { "ShipCountry" } }).Aggregates(agg=> { agg.Columns(new List<Syncfusion.EJ2.Grids.GridAggregateColumn>
() { new Syncfusion.EJ2.Grids.GridAggregateColumn() { Field = "Freight", Format = "C2", Type = "Sum", GroupFooterTemplate = "Sum: ${Sum}" } }).Add();
agg.Columns(new List<Syncfusion.EJ2.Grids.GridAggregateColumn>() { new Syncfusion.EJ2.Grids.GridAggregateColumn() { Field = "Freight", Format = "C2", Type = "Average", GroupCaptionTemplate = "Average: ${Average}" } }).Add(); }).Render()
public IActionResult Index()
{
var Order = Product.GetAllRecords();
ViewBag.DataSource = Order;
return View();
}
NOTE
The aggregate values must be accessed inside the template using their corresponding
Type
property ofGridAggregate Column
name.