http://blogs.infragistics.com/wpf/articles/creating-a-custom-summary-for-the-xamdatagrid.aspx
My first question is about this line of code in the above cited article:
SummaryCalculator.Register(Summary);
The article cited above says
"This can be achieved by not registering our summary like demonstrated above, but by associating a specific summary definition with a given column:"
"..the developer may want to show their custom summary on a specific field without placing it on every column. "
Emphisis on "not" and "every" is mine...........The article implies that there are two mutually exclusive methods for registering the summaries class ( second method cited in q2 below). When I follow the example I see no summaries at all however the second line quoted above leads me to think that following the example should not have the effect of doing nothing, but should instead display summaries on every column. Question: So when we do register the summary as shown in the article, what is accomplished? Is there additional code that needs to be added to make the article useful, or perhaps some xaml that is expected?
Question 2:
When i use this code I am able to get a summary row to display:
SummaryDefinition myTopSalesPersonFormula = new SummaryDefinition(); myTopSalesPersonFormula.SourceFieldName = "SalesYTD"; myTopSalesPersonFormula.Calculator = Summary; this.xamDataGrid1.FieldLayouts[0].SummaryDefinitions.Add(myTopSalesPersonFormula);
However, unlike the example, I get two rows of totals. I really only need one row, how do I remove the second row? I assume the second row is a subtotal row but I dont know that for sure and when I search for subtotals I find nothing relevent.
Question 3:
My specific question is how to remove the equal sign in front of the displayed total..... but more generally I would like to know what xaml (if any) is required to work with the code behind that is shown in the article. When I use the xaml that is shown in the feature explorer i.e.
<igDP:SummaryDefinition Key="Coupon" SourceFieldName="Coupon" Calculator="Sum">
I get yet a third row of of totals..................
Hello Sam,
Thank you for your post. I have been looking through it and I suggest you look through this forum thread:
http://community.infragistics.com/forums/p/57501/293454.aspx
where there is a sample project showing the implementation of a custom Summary calculator. You can also see here:
http://help.infragistics.com/NetAdvantage/WPF/2011.1/CLR4.0/?page=xamDataPresenter_Creating_a_Custom_Summary_Calculator.html
where it is described step by step how to do so. Please let me know if this helps you, if not, you can send me an isolated sample project and I will investigate it further for you.
Looking forward for your reply.
Thank you Sefan, Would you kindly address questions 1 and 2 above (most importantly #2)?
Regards,
Sam
Hello,
I am just checking the progress of this issue. Please let me know if I can provide you any further assistance.
Hi Stefan,
I do not want to display the summaries dropdown, I want the summary row to always appear (but only one row ). I am unable to determine how to accomplish this. Sorry for being so dense will you kindly assist me. Sorry but I dont know how to format code:<code>void PositionView_Loaded(object sender, RoutedEventArgs e) { // Add summary row expressions to FWPGrid.
PresentablePosition p = new PresentablePosition(); FWPGridSummary summary; SummaryDefinition def; List<KeyValuePair<string,Func<IList<PresentablePosition>, decimal>>> properties = new List<KeyValuePair<string,Func<IList<PresentablePosition>, decimal>>>(); properties.Add(new KeyValuePair<string,Func<IList<PresentablePosition>, decimal>>(Common.Utilities.PropertyName(() => p.OFace_Net), (x) => x.Sum(y => y.OFace_Net))); properties.Add(new KeyValuePair<string, Func<IList<PresentablePosition>, decimal>>(Common.Utilities.PropertyName(() => p.Qty_Net), (x) => x.Sum(y => y.Qty_Net))); properties.Add(new KeyValuePair<string, Func<IList<PresentablePosition>, decimal>>(Common.Utilities.PropertyName(() => p.OFace_Avail), (x) => x.Sum(y => y.OFace_Avail))); properties.Add(new KeyValuePair<string, Func<IList<PresentablePosition>, decimal>>(Common.Utilities.PropertyName(() => p.Qty_Avail), (x) => x.Sum(y => y.Qty_Avail))); properties.Add(new KeyValuePair<string, Func<IList<PresentablePosition>, decimal>>(Common.Utilities.PropertyName(() => p.WAC), (x) => Convert.ToDecimal(x.Sum(y => y.WAC)))); properties.Add(new KeyValuePair<string, Func<IList<PresentablePosition>, decimal>>(Common.Utilities.PropertyName(() => p.WAM), (x) => Convert.ToDecimal(x.Sum(y => y.WAM)))); properties.Add(new KeyValuePair<string, Func<IList<PresentablePosition>, decimal>>(Common.Utilities.PropertyName(() => p.Avg_LTV), (x) => Convert.ToDecimal(x.Sum(y => y.Avg_LTV)))); properties.Add(new KeyValuePair<string, Func<IList<PresentablePosition>, decimal>>(Common.Utilities.PropertyName(() => p.FICO), (x) => Convert.ToDecimal(x.Sum(y => y.FICO)))); properties.Add(new KeyValuePair<string, Func<IList<PresentablePosition>, decimal>>(Common.Utilities.PropertyName(() => p.WALA), (x) => Convert.ToDecimal(x.Sum(y => y.WALA)))); properties.Add(new KeyValuePair<string, Func<IList<PresentablePosition>, decimal>>(Common.Utilities.PropertyName(() => p.CPR1m), (x) => Convert.ToDecimal(x.Average(y => y.CPR1m)))); properties.Add(new KeyValuePair<string, Func<IList<PresentablePosition>, decimal>>(Common.Utilities.PropertyName(() => p.CPR3m), (x) => Convert.ToDecimal(x.Average(y => y.CPR3m)))); properties.Add(new KeyValuePair<string, Func<IList<PresentablePosition>, decimal>>(Common.Utilities.PropertyName(() => p.CPR6m), (x) => Convert.ToDecimal(x.Average(y => y.CPR6m)))); properties.Add(new KeyValuePair<string, Func<IList<PresentablePosition>, decimal>>(Common.Utilities.PropertyName(() => p.MedAvgLoanSize), (x) => Convert.ToDecimal(x.Sum(y => y.MedAvgLoanSize)))); properties.Add(new KeyValuePair<string, Func<IList<PresentablePosition>, decimal>>(Common.Utilities.PropertyName(() => p.MaxAvgLoanSize), (x) => Convert.ToDecimal(x.Sum(y => y.MaxAvgLoanSize)))); properties.Add(new KeyValuePair<string, Func<IList<PresentablePosition>, decimal>>(Common.Utilities.PropertyName(() => p.Duration), (x) => Convert.ToDecimal(x.Sum(y => y.Duration)))); properties.Add(new KeyValuePair<string, Func<IList<PresentablePosition>, decimal>>(Common.Utilities.PropertyName(() => p.Settled_OFace_Net), (x) => x.Sum(y => y.Settled_OFace_Net))); properties.Add(new KeyValuePair<string, Func<IList<PresentablePosition>, decimal>>(Common.Utilities.PropertyName(() => p.Settled_Qty_Net), (x) => x.Sum(y => y.Settled_Qty_Net))); properties.Add(new KeyValuePair<string, Func<IList<PresentablePosition>, decimal>>(Common.Utilities.PropertyName(() => p.Qty_Pledge), (x) => x.Sum(y => y.Qty_Pledge)));
foreach (KeyValuePair<string, Func<IList<PresentablePosition>, decimal>> kvp in properties) { summary = new FWPGridSummary(ViewModel, kvp.Value, kvp.Key, kvp.Key); def = new SummaryDefinition(); def.SourceFieldName = kvp.Key; def.Calculator = summary; def.Key = kvp.Key; def.StringFormat = "{0:C}"; def.DisplayArea = SummaryDisplayAreas.None | SummaryDisplayAreas.TopFixed; FWPGrid.FieldLayouts[0].SummaryDefinitions.Add(def); } } <igDP:XamDataGrid DataSource="{Binding Path=ViewManager.Items}" Grid.Row="1" AutoFit="True" ScrollingMode="Immediate" Name="FWPGrid" >
<i:Interaction.Triggers> <i:EventTrigger EventName="Sorting"> <galaExtras:EventToCommand Command="{Binding SortCriteriaChangedCommand, Mode=OneWay}" PassEventArgsToCommand="True"></galaExtras:EventToCommand> </i:EventTrigger> </i:Interaction.Triggers> <igDP:XamDataGrid.FieldSettings> <igDP:FieldSettings AllowEdit="False" Width="Auto" AllowRecordFiltering="False" AllowSummaries="False" SummaryDisplayArea="BottomFixed" SummaryUIType="MultiSelect" /> </igDP:XamDataGrid.FieldSettings> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AllowDelete="False" AllowAddNew="False" AllowFieldMoving="WithinLogicalRow" AutoGenerateFields="False" HighlightAlternateRecords="True" MaxSelectedRecords="1"/> </igDP:XamDataGrid.FieldLayoutSettings> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Fields> <igDP:Field Name="IncludeInTotals" Label="Totals"></igDP:Field> <igDP:Field Name="Acct_No" Label="Acct No"/> <igDP:Field Name="CUSIP" Label="CUSIP"/> </code>
Hi again,
As far as I understand you, you want to have a summary row on project start, but you don’t want to have a dropdown and allow user to make summaries. If that so, I created a sample project for you showing how to do this. Please let me know if this is what you are trying to achieve or I have misunderstood you in some way.
Hi Sefan, Thank you for your help. You found the problem but your code does not illustrate a solution. Please use the following in MainWindow.xaml to illustrate:
<Window x:Class="CustomSummaryCalculator.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:igWindows="http://infragistics.com/Windows" Title="MainWindow" Height="350" Width="525" xmlns:igDP="http://infragistics.com/DataPresenter"> <Grid> <igWindows:XamTabControl TabItemCloseButtonVisibility="Hidden"> <igWindows:TabItemEx Header="Tab 1"> <igDP:XamDataGrid Loaded="xamDataGrid1_Loaded" Name="xamDataGrid1" VerticalAlignment="Top"> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Fields> <igDP:Field Name="Name" Label="Name"></igDP:Field> <igDP:Field Name="Salary" Label="Salary"></igDP:Field> <igDP:Field Name="Age" Label="Age"></igDP:Field> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid> </igWindows:TabItemEx> <igWindows:TabItemEx Header="Tab 2"> <TextBlock Text="This is tab 2"></TextBlock> </igWindows:TabItemEx> </igWindows:XamTabControl> </Grid></Window>
I think you have to unwire the load event inside the handler.
I have tried to remove pretty much everything from the usercontrol, but still only get the default summary. There has to be something in our toolkit that is causing the problem. Can you give me any hints. Maybe if I override a style so I do not get the default, but I need to know what the name of the style is.
Help would be very much appreciated.
Clifford
There is no way I can modify the sample, since it works fine. I have moved my SummaryCalculator to the sample and it works. I have tried removing allmost all the xaml from my code and it does not work. SInce I depend on a database you will not be able to run the code. I suspect there is some property in our toolkit that is causing the problem, but I do not have ready access to that code. If I have some idea, I can override the property. I can obviously just create a style and then bypass any toolkit effect, but need to know what to override.
Thanks
Could you pelase modify the sample I have sent in my previous post, so it reproduces your behavior, so i could be able to investigate this further for you.
I tried to use the sample to provide a custom format in a class derrived from SummaryCalculator, adn overriding the ApplyDefaultFormat, but still not getting the value from the ApplyDefaultFormat method. The method is called, but seems to have no effect. Any ideas?
I used the code you have provided and I made some changes to the sample project, so now the summary is added only once. Basically I defined an isAdded variable which I set to true, when I add the summary and then in the Load event I check its value. Please let me know if you need further assistance on this matter.