How to extract the summary row's calculated text such as sum values and dynamically display that in the Grouped Row's caption text

I am working on a SfDataGrid that has a grouping row by a specific field and a summary row placed on the bottom that sums up column values. How can I extract the calculated text of the summary row and also add that summary text to the caption text of the grouped rows in the SfDataGrid?

For instance, I want to get the final calculated text "5 10 15 20" from the SummaryRow of the SfDataGrid and update my grouped row caption text format with those values.


1 Reply

MS Malini Selvarasu Syncfusion Team April 17, 2025 02:25 PM UTC

Hi  Eric Nguyen,

Based on the information provided, we understand that you would like to retrieve the final calculated text, such as "5 10 15 20", from the SummaryRow of the SfDataGrid and update the grouped row caption text format with these values. This can be accomplished by retrieving the table summary row text using the GetSummaryDisplayText method and updating the caption summary row text using the SfDataGrid.GroupCaptionTextFormat property.

To assist you further, we have prepared a sample that demonstrates this approach. Please refer to the following code snippet:
C# code snippet:
private void DataGrid_Loaded(object sender, RoutedEventArgs e)
{
    var summary = this.dataGrid.View.Records.TableSummaries[0];
    var summaryValues = new List<string>();
 
    foreach (var column in dataGrid.Columns)
    {
        var value = SummaryCreator.GetSummaryDisplayText(summary, column.MappingName, this.dataGrid.View);
 
        // Only add if the summary value is not null or empty
        if (!string.IsNullOrWhiteSpace(value))
        {
            summaryValues.Add(value);
        }
    }
    string customText = string.Join(" ", summaryValues);
    dataGrid.GroupCaptionTextFormat = "Totals: " + customText;
}

Find the sample demo in the attachment.
Please let us know if this solution meets your requirements.

If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.

Regards,
Malini Selvarasu

Attachment: SfDataGrid_Demo_386b04c0.zip

Loader.
Up arrow icon