Articles in this section
Category / Section

How to Customize Caption Summary Row Template in MAUI DataGrid?

7 mins read

In this article, we will show you how to customize the caption summary row template with grouping in the .NET MAUI DataGrid.

xaml
The code below demonstrates how to customize the caption summary row template with grouping in DataGrid.

 <ContentPage.BindingContext>
    <local:EmployeeViewModel x:Name="viewModel" />
</ContentPage.BindingContext>

<ContentPage.Resources>
    <ResourceDictionary>
        <local:GroupCaptionConverter x:Key="SummaryConverter" />
    </ResourceDictionary>
</ContentPage.Resources>

<syncfusion:SfDataGrid x:Name="dataGrid"
                       Margin="10"
                       GridLinesVisibility="Both"
                       HeaderGridLinesVisibility="Both"
                       ColumnWidthMode="Auto"
                       AllowGroupExpandCollapse="True"
                       GroupingMode="Single"
                       AutoGenerateColumnsMode="None"
                       ItemsSource="{Binding Employees}">

    <syncfusion:SfDataGrid.GroupColumnDescriptions>
        <syncfusion:GroupColumnDescription ColumnName="Salary" />
    </syncfusion:SfDataGrid.GroupColumnDescriptions>

    <syncfusion:SfDataGrid.CaptionSummaryTemplate>
        <DataTemplate>
            <StackLayout Orientation="Horizontal">
                <Label Text="{Binding Converter={StaticResource SummaryConverter}, ConverterParameter = {x:Reference dataGrid} }"
                       FontSize="Default"
                       VerticalTextAlignment="Center"
                       HorizontalTextAlignment="Start"
                       LineBreakMode="NoWrap"
                       HorizontalOptions="FillAndExpand"
                       VerticalOptions="FillAndExpand">
                    <Label.Style>
                        <Style TargetType="Label">
                            <Setter Property="FontAttributes"
                                    Value="Bold, Italic" />
                            <Setter Property="TextColor"
                                    Value="Orange" />
                        </Style>
                    </Label.Style>
                </Label>
            </StackLayout>
        </DataTemplate>
    </syncfusion:SfDataGrid.CaptionSummaryTemplate>
    <syncfusion:SfDataGrid.CaptionSummaryRow>
        <syncfusion:DataGridSummaryRow Name="CaptionSummary"
                                       ShowSummaryInRow="True"
                                       Title="Total Salary: {CaptionSummary}">
            <syncfusion:DataGridSummaryRow.SummaryColumns>
                <syncfusion:DataGridSummaryColumn Name="CaptionSummary"
                                                  Format="{}{Sum:C0}"
                                                  MappingName="Salary"
                                                  SummaryType="DoubleAggregate" />
            </syncfusion:DataGridSummaryRow.SummaryColumns>
        </syncfusion:DataGridSummaryRow>
    </syncfusion:SfDataGrid.CaptionSummaryRow>

    <syncfusion:SfDataGrid.Columns>
        <syncfusion:DataGridNumericColumn MappingName="EmployeeID"
                                          Format="#"
                                          HeaderText="Employee ID" />
        <syncfusion:DataGridTextColumn MappingName="Name"
                                       HeaderText="Employee Name" />
        <syncfusion:DataGridTextColumn MappingName="Title"
                                       HeaderText="Designation" />
        <syncfusion:DataGridNumericColumn MappingName="Salary"
                                          HeaderText="Salary" />

    </syncfusion:SfDataGrid.Columns>

</syncfusion:SfDataGrid>

C#

public class GroupCaptionConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        var data = value != null ? value as Group : null;
        if (data != null)
        {
            SfDataGrid dataGrid = (SfDataGrid)parameter;
            var summaryText = SummaryCreator.GetSummaryDisplayTextForRow((value as Group).SummaryDetails, dataGrid.View);

            return summaryText;
        }
        return null;
    }
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return null;
    }
}

Output

CaptionRowTemplate.png

Download the complete sample from GitHub.

Conclusion

I hope you enjoyed learning how to customize the caption summary row template in .NET MAUI DataGrid.

You can refer to our .NET MAUI DataGrid feature tour page to learn about its other groundbreaking feature representations and Documentation, and how to quickly get started with configuration specifications. Explore our .NET MAUI DataGrid example to understand how to create and manipulate data.

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

Please let us know in the comments section if you have any queries or require clarification. You can also contact us through our support forums, Direct-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  to leave a comment
Access denied
Access denied