How To Combine Group Caption Details With Custom Summary Results In One Line
I have a SfDataGrid that is grouping columns by a specific mapping name. My implementation uses a GridSummaryColumn to compute a custom aggregate value and places it inside a GridSummaryRow so that the summary calculates the result for each group. I do not want this Grid Summary value however to be on the bottom of the grouped rows, but instead at the top of the row in the same place as the Group Caption Summary. I want this Grid Summary value to be aligned on the same column the custom aggregate value is being calculated on. The grid summary aggregate value needs to be aligned at the same column it aggregated on, in the caption text summary. I also need this caption text to have the text of the dynamic column name the rows are grouped by, and the number of rows. So it should look like the following:
{DynamicGroupedColumnName} ({RowCount} Rows) | Custom Aggregate: 23 Custom Aggregate: 56
The Custom Aggregate summary values in the caption summary should be aligned at the columns it's summarizing.
<syncfusion:SfDataGrid.CaptionSummaryRow> <syncfusion:GridSummaryRow Title="[{ColumnName}: {Key} – {ItemsCount} Rows | Custom Aggregate:" ShowSummaryInRow="False" TitleColumnCount="3"> <syncfusion:GridSummaryRow.SummaryColumns > <syncfusion:GridSummaryColumn Name="TotalQuantity" SummaryType="Custom" CustomAggregate="{StaticResource customAggregate}" Format="'{TotalQuantity}'" MappingName="Quantity"/> </syncfusion:GridSummaryRow.SummaryColumns> </syncfusion:GridSummaryRow> </syncfusion:SfDataGrid.CaptionSummaryRow> |
Attachment: Sample_8c9c2aac.zip
Thank you, is it possible to create a column span greater than one for a column in the CaptionSummaryRow?
I looked at other syncfusion solutions per previous solution. I am currently using a custom GridCaptionSummaryCellRenderer class to assign the content of each column cell for the CaptionSummaryRow, but the first column text would get cut off. If I use the default GridCaptionSummaryCellRenderer, then the first column text not get cut off.
public class CaptionSummaryRenderer : GridCaptionSummaryCellRenderer { public override void OnUpdateEditBinding(DataColumnBase dataColumn, GridCaptionSummaryCell element, object dataContext) { base.OnUpdateEditBinding(dataColumn, element, dataContext); var groupRecord = element.DataContext as Group; if (groupRecord == null) return; var groupedColumn = this.GetGroupedColumn(groupRecord); if (groupedColumn == null) return; var summaryValue = groupRecord.GetSummaryValue(dataColumn.GridColumn.MappingName); element.Content = groupedColumn.HeaderText + ":" + groupRecord.Key +" " + groupRecord.ItemsCount + " " + "rows" + " "+"CustomAggregate" + ":" + summaryValue; double textWidth = MeasureTextWidth(element.Content.ToString(), element); dataColumn.GridColumn.Width = textWidth + 10; } private static double MeasureTextWidth(string text, GridCaptionSummaryCell element) { var tb = new TextBlock { Text = text, FontFamily = element.FontFamily, FontSize = element.FontSize, FontWeight = element.FontWeight }; tb.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); return tb.DesiredSize.Width; } } |
Attachment: Sample_afc36d88.zip
- 3 Replies
- 2 Participants
-
EN Eric Nguyen
- Dec 10, 2025 02:17 PM UTC
- Dec 12, 2025 01:44 PM UTC