How to Customize the Table Summary Row in .NET MAUI DataGrid?
This article demonstrates how to customize the table summary row in the .NET MAUI DataGrid. You can enhance the appearance and functionality of the DataGrid’s summary row with custom styling and behavior.
Xaml
<ContentPage.BindingContext>
<local:EmployeeViewModel x:Name="viewModel" />
</ContentPage.BindingContext>
<syncfusion:SfDataGrid x:Name="sfGrid"
GridLinesVisibility="Both"
HeaderGridLinesVisibility="Both"
ColumnWidthMode="Auto"
AutoGenerateColumnsMode="None"
ItemsSource="{Binding Employees}">
<syncfusion:SfDataGrid.TableSummaryRows>
<syncfusion:DataGridTableSummaryRow Title="Total Salary :{TotalSalary} for {ProductCount} members"
ShowSummaryInRow="True">
<syncfusion:DataGridTableSummaryRow.SummaryColumns>
<syncfusion:DataGridSummaryColumn Name="TotalSalary"
Format="{}{Sum:C0}"
MappingName="Salary"
SummaryType="DoubleAggregate" />
<syncfusion:DataGridSummaryColumn Name="ProductCount"
Format="{}{Count}"
MappingName="Salary"
SummaryType="CountAggregate" />
</syncfusion:DataGridTableSummaryRow.SummaryColumns>
</syncfusion:DataGridTableSummaryRow>
</syncfusion:SfDataGrid.TableSummaryRows>
<syncfusion:SfDataGrid.Columns>
<syncfusion:DataGridTextColumn MappingName="Name"
HeaderText="Employee Name" />
<syncfusion:DataGridTextColumn MappingName="Title"
HeaderText="Designation" />
<syncfusion:DataGridTextColumn MappingName="LoginID"
HeaderText="Login ID" />
<syncfusion:DataGridTextColumn MappingName="Salary"
HeaderText="Salary" />
</syncfusion:SfDataGrid.Columns>
</syncfusion:SfDataGrid>
Xaml.cs
The following code demonstrates how to customize the table summary row using a custom renderer in SfDataGrid.
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
sfGrid.CellRenderers.Remove("TableSummary");
sfGrid.CellRenderers.Add("TableSummary", new TableSummaryCellRenderer());
}
}
public class TableSummaryCellRenderer : DataGridTableSummaryCellRenderer
{
protected override void OnSetCellStyle(DataColumnBase dataColumn)
{
base.OnSetCellStyle(dataColumn);
if (dataColumn.ColumnElement != null && dataColumn.ColumnElement.Content is SfDataGridLabel label)
{
dataColumn.ColumnElement.Background = Colors.SkyBlue;
label.HorizontalTextAlignment = TextAlignment.Start;
label.FontSize = 16;
label.FontAttributes = FontAttributes.Bold;
label.TextColor = Colors.White;
}
}
}
Output
Download the complete sample from GitHub.
Conclusion
I hope you enjoyed learning how to customize the table summary row in .NET MAUI DataGrid.
You can refer to our .NET MAUI DataGrid feature tour page to learn about its other groundbreaking feature representations. Explore our .NET MAUI DataGrid Documentation to understand how to present and manipulate data.
For current customers, you can check out our .NET MAUI components on the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to explore our .NET MAUI DataGrid and other .NET MAUI components.
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, or the feedback portal. We are always happy to assist you!