Articles in this section
Category / Section

How to apply different styles to the GridTableSummaryRow in UWP DataGrid?

1 min read

The UWP DataGrid provides option to display the TableSummary, either at the top or bottom of the SfDataGrid by setting the GridTableSummaryRow.Position property. It is possible to apply different styles for the top and bottom table summaries by using the StyleSelector and by setting the SfDataGrid.TableSummaryRowStyleSelector property. This is demonstrated in the following code example.

<!--Adds the code example in the Resources Define with Key-->.
<local:TableSummaryStyleSelector x:Key="tableSummaryStyleSelector" />
<Syncfusion:SfDataGrid x:Name="SfdataGrid"
                       TableSummaryRowStyleSelector="{StaticResource tableSummaryStyleSelector}"
                       ItemsSource="{Binding GDCSource}"
                       AutoGenerateColumns="False">
    <Syncfusion:SfDataGrid.TableSummaryRows>
        <Syncfusion:GridTableSummaryRow Position="Top" ShowSummaryInRow="False">
            <Syncfusion:GridTableSummaryRow.SummaryColumns>
                <Syncfusion:GridSummaryColumn Name="EmployeeSalary"
                                                  Format="'{Sum:c}'"
                                                  MappingName="EmployeeSalary"
                                                  SummaryType="Int32Aggregate" />
            </Syncfusion:GridTableSummaryRow.SummaryColumns>
        </Syncfusion:GridTableSummaryRow>
        <Syncfusion:GridTableSummaryRow Position="Bottom" Title="Total EmployeeCount : {EmployeeCount}" ShowSummaryInRow="True">
            <Syncfusion:GridSummaryRow.SummaryColumns>
                <Syncfusion:GridSummaryColumn Name="EmployeeCount"
                                  Format="'{Count:d}'"
                                  MappingName="EmployeeName"
                                  SummaryType="Int32Aggregate" />
            </Syncfusion:GridSummaryRow.SummaryColumns>
        </Syncfusion:GridTableSummaryRow>
    </Syncfusion:SfDataGrid.TableSummaryRows>
</Syncfusion:SfDataGrid>

 

Two different table summary styles are defined in the Application.Resources.

<Application.Resources>
    <Style x:Key="TableSummaryStyle1" TargetType="Syncfusion:TableSummaryRowControl">
        <Setter Property="Foreground" Value="Red" />
    </Style>
    <Style x:Key="TableSummaryStyle2" TargetType="Syncfusion:TableSummaryRowControl">
        <Setter Property="Foreground" Value="Blue" />
    </Style>
</Application.Resources>

 

Different styles are applied to the GridTableSummaryRow based on the GridTableSummaryRow.Position.

public class TableSummaryStyleSelector : StyleSelector
{
    public override Style SelectStyle(object item, DependencyObject container)
    {
        var rowData = (item as SpannedDataRow).RowData;
        var summaryRecordEntry = rowData as SummaryRecordEntry;
        var gridTableSummaryRow = summaryRecordEntry.SummaryRow as GridTableSummaryRow;
        if (gridTableSummaryRow.Position == TableSummaryRowPosition.Top)
        {
            return App.Current.Resources["TableSummaryStyle1"] as Style;
        }
        else if (gridTableSummaryRow.Position == TableSummaryRowPosition.Bottom)
        {
            return App.Current.Resources["TableSummaryStyle2"] as Style;
        }
        return null;
    }
}

 

In the following screenshot, the different styles are applied to the different GridTableSummaryRows.

Grid summary Row in Top and Botton

 

 

Sample Links:

 

WPF

 

WinRT

 

UWP


Conclusion

I hope you enjoyed learning about how to apply different styles to the GridTableSummaryRow in UWP DataGrid.

You can refer to our UWP DataGrid feature tourpage to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our UWP DataGrid example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied