How to have multiple distinct GridSummaryColumn types with the same Name property value and same SummaryType property value
I am attempting to add multiple GridSummaryColumn objects to a SfDataGrid in a codebehind control that extends SfDataGrid. For each GridSummaryColumn, they share the same Name property Value and the same SummaryType value.
The SfDataGrid displays multiple columns that have the same display name. I need each of those columns to have its respective sum summary. The problem is that the summary row only shows the sum value for the first column name, not each of them distinctly.
I need each SummaryColumn to have duplicate Name and SummaryType property values but have distinct MappingName property values.
My example code is the following:
GridTableSummaryRow summaryRow = new GridTableSummaryRow();
GridSummaryColumn summaryColumn1 = new GridSummaryColumn
{
Name = "testName",
Mapping = "differentValue1",
SummaryType = Syncfusion.Data.SummaryType.DoubleAggregate
};
GridSummaryColumn summaryColumn2 = new GridSummaryColumn
{
Name = "testName",
Mapping = "differentValue2",
SummaryType = Syncfusion.Data.SummaryType.DoubleAggregate
};
GridSummaryColumn summaryColumn3 = new GridSummaryColumn
{
Name = "testName",
Mapping = "differentValue3",
SummaryType = Syncfusion.Data.SummaryType.DoubleAggregate
};
summaryRow.SummaryColumns = new ObservableCollection<Syncfusion.Data.ISummaryColumn> { summaryColumn1, summaryColumn2, summaryColumn3 };
TableSummaryRows.Add(summaryRow);
Hi Eric Nguyen,
As we analyzed the provided code snippet, you have maintained
three grid summary columns with the same Name property and the same
SummaryType, but different MappingName values.
We would like to inform you that since the MappingName values are different, each summary column must have a unique Name. This ensures that all summary columns are displayed correctly.
Code Snippet:
|
GridTableSummaryRow summaryRow = new GridTableSummaryRow(); summaryRow.ShowSummaryInRow = false;
GridSummaryColumn summaryColumn1 = new GridSummaryColumn { Name = "testName1", MappingName = "DifferentValue1", SummaryType = Syncfusion.Data.SummaryType.DoubleAggregate, Format = "Sum: {Sum:N2}" //Format = "{Sum:c}" };
GridSummaryColumn summaryColumn2 = new GridSummaryColumn { Name = "testName2", MappingName = "DifferentValue2", SummaryType = Syncfusion.Data.SummaryType.DoubleAggregate, Format = "Sum: {Sum:N2}" };
GridSummaryColumn summaryColumn3 = new GridSummaryColumn { Name = "testName3", MappingName = "DifferentValue3", SummaryType = Syncfusion.Data.SummaryType.DoubleAggregate, Format = "Sum: {Sum:N2}" };
summaryRow.SummaryColumns = new ObservableCollection<Syncfusion.Data.ISummaryColumn> { summaryColumn1,summaryColumn2,summaryColumn3 };
dataGrid.TableSummaryRows.Add(summaryRow);
|
For your reference, we have attached the modified sample and a user guide link for handling "Summaries." Kindly refer to it.
https://help.syncfusion.com/wpf/datagrid/summaries?cs-save-lang=1&cs-lang=csharp#defining-summary-for-column
Output:
If we misunderstood your requirements, please provide more details. It will
help us to proceed further.
Regards,
Santhosh.G
Attachment: SfDataGrid_Demo_335c2f84.zip
- 1 Reply
- 2 Participants
-
EN Eric Nguyen
- Feb 11, 2025 10:00 PM UTC
- Feb 12, 2025 06:12 AM UTC