I have data in a XamDataGrid grouped by a particular column. I also have a row summary which shows the Count of all records in each group and also a Count of all records in the entire grid.
I can change the summary's display name using the StringFormat but what if I want the summary for the entire grid to have a different display name to the summaries in the group by records?
Hello Rajib,
This link points to a old version of our documentation and this is why it isn't working. Here is a working one:
http://help.infragistics.com/Help/Doc/WPF/2014.2/CLR4.0/html/xamDataPresenter_Creating_a_Custom_Summary_Calculator.html
http://help.infragistics.com/Help/NetAdvantage/WPF/2010.2/CLR4.0/html/xamDataPresenter_Creating_a_Custom_Summary_Calculator.html link is not working
I had a need to accomplish the same thing and found a workaround to do it. It is likely too late for the original poster, but I'll share the solution here in case anyone happes to be searching for an answer on how to do this.
The key is to create a custom summary calculator that returns the string value you wish to use as a label in the summary or grand summary row.
A good tutorial on creating a custom summary calculator can be found here: http://help.infragistics.com/Help/NetAdvantage/WPF/2010.2/CLR4.0/html/xamDataPresenter_Creating_a_Custom_Summary_Calculator.html
Say for example you have a grid of sales grouped by region; North, South, East and West and you would like each groupbysummary row to have a label such as "North Subtotal" or "South Subtotal". On the grandsummary row you would like the label "Grand Total".
In your custom summary calculator code, in the Aggregate method, you need to keep track of what group category the current calculation is being performed on. In this example, SaleItem is a custom class within an ObservableCollection that is bound to the grid.
public override void Aggregate(object dataValue, SummaryResult summaryResult, Record record) { // You only need this if you want custom subtotal category labels for each group. DataRecord dataRecord = record as DataRecord; SaleItem saleitem = dataRecord.DataItem as SaleItem;
_category = saleitem.CategoryDescription; }
Then in the EndCalculation method, you can inspect the summaryResult parameter to determine if you are returning the result of a groupby summary or the grand summary. I found the following through trial and error and stepping through the code with a debugger, so keep in mind this is not a proven or guaranteed solution. You can get the name of the type of summaryResult.ParentCollection.Records and if it is "RecordCollection" you set the label that you want to see for a groupbysummary row, otherwise set the label you want to use for the grandsummary row.
public override object EndCalculation(SummaryResult summaryResult) { string retVal;
object o = summaryResult.ParentCollection.Records;
if (o.GetType().Name == "RecordCollection") // You could return a custom label for each grouping... retVal = _category + " Subtotal";
// ... or alternatively, you could just return a plain Subtotal label. //retVal = "Subtotal"; else retVal = "Grand Total";
return retVal; }
Once you have your custom summary calculator written (make sure you register it as in the turorial!) you can apply it to your grid XAML code.
<igDP:SummaryDefinition Key="SubtotalSummaryCategory" SourceFieldName="CategoryDescription" Calculator="CustomLabelCalc" StringFormat="{}{0}"></igDP:SummaryDefinition>
Hope this helps others facing this challenge, or at least gets them started down the path to a solution of their own.
Thank you very much for your response and efforts. I have submitted a feature request as you suggested.
Hello,
Unfortunately, the functionality that you would like is not supported by the XamDataGrid. I have tried a few thigs, but they will not work:
1) If you loop through the GroupByRecord.ChildRecords collecition, you can get access to the StringFormat property for the childRecords.
gbr.ChildRecords.SummaryResults.SummaryDefinitions[0].StringFormat = "Total{0:c}".
However, changing this here will ultimately change the SummaryDefinition for the entire fieldLayout causing the grand total StringFormat to change also.
2) I was also looking into changing the format of the SummaryCellPresenter object via style and trigger, but there was no way to figure out if the SummaryCell was part of a GroupByRecordCollection or not.
Because this type of behavior is not supported, I have submitted a FeatureRequest for either having the SummaryDefinitions on a record collection basis or to have a property on the SummaryCellPresenter that will tell me if the summary is part of a group by collection so a trigger can be used to change the format.
If you would like, please submit your own request. The more requests, the better chance the feature will be implemented soon.
Thank you for using the Infragistics Formums and have a nice day.