ComponentOne FlexGrid for UWP
Features / Aggregating Data
In This Topic
    Aggregating Data
    In This Topic

    When your grid is populated with certain types of data, such as sales data, you may want certain categories to be aggregated, such as sales data by country or product.

    You can accomplish this easily with the C1FlexGrid control. You can simply set the GroupAggregate property on the columns you want to aggregate, either in XAML markup or in code. Once you set the property, C1FlexGrid will automatically calculate and display the aggregates in the group header rows.

    This is apparent in the following grid definition:

    XAML
    Copy Code
    <c1:C1FlexGrid x:Name="c1FlexGrid1" AutoGenerateColumns="False" ShowOutlineBar="True" BorderThickness="1">
        <c1:C1FlexGrid.Columns>
            <c1:Column Binding="{Binding Name}" Width="*"/>
            <c1:Column Binding="{Binding Line}" />
            <c1:Column Binding="{Binding Color}" />
            <c1:Column Binding="{Binding Price}" Format="c2" Width="*"/>
            <c1:Column Binding="{Binding Weight}" Format="n2" Width="*" />
            <c1:Column Binding="{Binding Cost}" Format="c2" Width="*"/>
            <c1:Column Binding="{Binding Volume}" Width="*"/>
            <c1:Column Binding="{Binding Rating}" Format="n2" Width="*"/>
            <c1:Column Binding="{Binding Discontinued}" Width="*"/>
        </c1:C1FlexGrid.Columns>
    </c1:C1FlexGrid>
    

    You can group items in your C1FlexGrid if you set the ItemsSource property to a C1CollectionView object configured to group the data by product line. Follow this link to see how you can perform grouping before you aggregate your data:

     

     

    FlexGrid allows you to go further than just grouping items. If you wanted to display totals for the Price, Weight, Cost, Volume, and Rating columns, your XAML markup would resemble the following:

    XAML
    Copy Code
    <c1:C1FlexGrid x:Name="c1FlexGrid1" AutoGenerateColumns="False" ShowOutlineBar="True" BorderThickness="1">
        <c1:C1FlexGrid.Columns>
            <c1:Column Binding="{Binding Name}" Width="*"/>
            <c1:Column Binding="{Binding Line}" />
            <c1:Column Binding="{Binding Color}" />
            <c1:Column Binding="{Binding Price}" Format="c2" GroupAggregate="Sum" Width="*"/>
            <c1:Column Binding="{Binding Weight}" Format="n2" GroupAggregate="Sum" Width="*" />
            <c1:Column Binding="{Binding Cost}" Format="c2" GroupAggregate="Sum" Width="*"/>
            <c1:Column Binding="{Binding Volume}" GroupAggregate="Sum" Width="*"/>
            <c1:Column Binding="{Binding Rating}" Format="n2" GroupAggregate="Average" Width="*"/>
            <c1:Column Binding="{Binding Discontinued}" Width="*"/>
        </c1:C1FlexGrid.Columns>
    </c1:C1FlexGrid>
    

    Note that the Rating column is set to aggregate as an average. After you make this change, your C1FlexGrid control will resemble the following image:

     

     

    Your column headers should display the aggregate values for each column.