@model IEnumerable<FlexGridData.Sale>

<h1>
    Custom Aggregates
</h1>
<p>
    FlexGrid columns have an <b>aggregate</b> property that
    allows you to show data summaries for the whole grid or
    for each group.
</p>
<p>
    However, in some cases, the <b>aggregate</b> property is
    not flexible enough. So, you may need to calculate
    aggregates using custom code.
</p>
<p>
    The grid below includes a 'Profit' column that shows
    the difference between 'Sales' and 'Expenses'.
</p>
<p>
    The 'Profit' column is calculated in the <b>formatItem</b>
    event. The profit for regular data items is based on
    the actual data items. The profit for groups is calculated
    using the group's <b>getAggregate</b> method.
</p>
@(Html.C1().FlexGrid<FlexGridData.Sale>().Id("theGrid").Height(250)
    .AutoGenerateColumns(false)
    .Bind(Model)
    .Columns(cs =>
    {
        cs.Add().Binding("Id").Header("ID").Width("60").IsReadOnly(true);
        cs.Add().Binding("Country").Header("Country");
        cs.Add().Binding("Product").Header("Product");
        cs.Add().Binding("Sales").Header("Sales").Aggregate(C1.Web.Mvc.Grid.Aggregate.Sum);
        cs.Add().Binding("Expenses").Header("Expenses").Aggregate(C1.Web.Mvc.Grid.Aggregate.Sum);
        cs.Add().Binding("Profit").Header("Profit").DataType(C1.Web.Mvc.Grid.DataType.Number).IsReadOnly(true);
    })
)