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?
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.
http://help.infragistics.com/Help/NetAdvantage/WPF/2010.2/CLR4.0/html/xamDataPresenter_Creating_a_Custom_Summary_Calculator.html link is not working
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