I am loading a large datasource into a XamDataGrid and in the FieldLayoutInitialized event handler I'm defining some SummaryDefinition based on Property Attributes.
foreach (var columnDetailsAttribute in attributes.Where(attribute => attribute.TotalsBy || attribute.AverageBy)){ var summaryDefinition = new SummaryDefinition(); summaryDefinition.SourceFieldName = columnDetailsAttribute.PropertyName; summaryDefinition.Calculator = columnDetailsAttribute.TotalsBy ? (SummaryCalculator) Infragistics.Windows.DataPresenter.SummaryCalculator.Sum : Infragistics.Windows.DataPresenter.SummaryCalculator.Average; e.FieldLayout.SummaryDefinitions.Add(summaryDefinition);}
this works fine.
However I would like to turnoff or not define the SummaryDefinition if the grouping only has one group.
Hello ahrensd,
Thank you for your post!
I have been looking into your issue and it seems that I am missing something from your scenario. Would you please provide me with more detailed information about the functionality you are using? Also if possible would you please provide me with small sample application, that shows the functionality you are using?
Having this information would help me further investigate this matter for you.
Looking forward to hearing from you.
Gergana,
I have a IEnumerable<DataType> where the DataType has upto 20 properties. The IEnumerable has between 10 to 1000 items. I'm grouping the data by upto 4 properties of the DataType. This is fine when there is 1000+ items, all the groups make sense. However when there are only 10 items, 2 of the groups are not required. So I would like to examine the groupings and if the group only contains one group, then remove, turn off or set a setting that stops XamDataGrid to not allow groups with only one group.
Sorry just realised that I pasted the wrong code snippet in my original post.
I'm doing it just before I'm doing the summaries with this:
if (attributes.Any(attribute => attribute.GroupBy)){ if (!XamDataGrid.Resources.Contains("ColourKey")) { var datatype = typeof (GroupByRecordPresenter); var style = new Style(datatype); style.Resources.Add(new ComponentResourceKey(typeof (XamDataGrid), "LabelHighlight"), new SolidColorBrush(Colors.Transparent)); style.Resources.Add(new ComponentResourceKey(typeof (XamDataGrid), "LabelBackground"), new SolidColorBrush(Colors.Transparent)); foreach (var source in attributes.Where(attribute => attribute.GroupBy).OrderBy(attribute => attribute.Order)) { var brush = new LinearGradientBrush() { Opacity = 0.5, StartPoint = new Point(0.5,0), EndPoint = new Point(0.5,1)}; brush.GradientStops.Add(new GradientStop(Colors.Snow, 0)); if (source.ColourBinding) { var stop = new GradientStop(source.ColourCodeFinish, 0.9); var binding = new Binding("ChildRecords[0].DataItem." + attributes.FirstOrDefault(attribute => attribute.ColourBound).PropertyName); BindingOperations.SetBinding(stop, GradientStop.ColorProperty, binding); brush.GradientStops.Add(stop); } else { brush.GradientStops.Add(new GradientStop(source.ColourCodeStart, 0.1)); brush.GradientStops.Add(new GradientStop(source.ColourCodeFinish, 0.9)); } e.FieldLayout.SortedFields.Add(new FieldSortDescription(source.PropertyName, ListSortDirection.Ascending, true)); brush.GradientStops.Add(new GradientStop(Colors.Snow, 1)); var trigger = new DataTrigger() {Value = source.PropertyName}; trigger.Binding = new Binding("GroupByField.Name") { BindsDirectlyToSource = true }; trigger.Setters.Add(new Setter(BackgroundProperty, brush)); style.Triggers.Add(trigger);
} XamDataGrid.Resources.Add("ColourKey", style); } var statbinding = new Binding() { Source = XamDataGrid.Resources["ColourKey"], BindsDirectlyToSource = true }; BindingOperations.SetBinding(XamDataGrid.FieldSettings, FieldSettings.GroupByRecordPresenterStyleProperty, statbinding);}
Thanks for your time Gergana,
Your modified code didn't quite cut it, but did put me on the right track, which I would never of found without your help.
After some further alterations I have something that behaves how I wanted.
Any improvements welcomed, how about putting the functionality directly in the library?
Regards David
Hello David,
Thank you for the feedback. I am glad that you have found a solution to your issue.
I have been looking into your question about putting this functionality directly in the library - if you would like this functionality to be included as a built-in functionality in our controls in a future version I can suggest creating a new Product Idea on the following site http://ideas.infragistics.com.
If you create a new Product Idea you would be able to discuss this functionality with our developers. Also you would receive notifications regarding the status of the idea.
Please do not hesitate to let me know if you have any further questions on this matter.
Have used this code for my application and it doesn't work when you programmiclly add the FieldSortDescription's in the FieldLayoutInitialized.
Close but doesn't call igDataGrid_Grouping in this case.
I have been looking into your issue.
Currently the Grouping and Grouped event of the XamDataGrid fire when the user groups the records through the UI. More about those events you can find on the following link from our documentation:
http://help.infragistics.com/Help/Doc/WPF/2015.1/CLR4.0/html/InfragisticsWPF4.DataPresenter.v15.1~Infragistics.Windows.DataPresenter.XamDataGrid_members.html.
If you want to set the FieldSortDescription in the FieldLayoutInitialized I could suggest using the Loaded event of the XamDataGrid to check the items in a group.
I am just checking if you have any further questions on this matter. Please do not hesitate to let me know if you do.