Hi,
I'm trying to use grouping feature of xamdatagrid. I would like to do initial default grouping by three fields and then allow user to rearrange or group accordingly as he wishes. Is that something that is possible? I'm using ListCollectionView and SortEvaluationMode = 'UseColllectionView'
Thanks
Hello RJ,
In order to initially group the XamDataGrid when using a collection view, I would recommend that you add a new PropertyGroupDescription to the GroupDescriptions collection of your ListCollectionView. Note, in order for this to work correctly, you will also need to set the GroupEvaluationMode property of your XamDataGrid.FieldLayoutSettings to "UseCollectionView." This essentially delegates the grouping work back to the collection view that is used as the DataSource of your XamDataGrid.
As an alternative, you can go without setting the UseCollectionView setting in this case, and add new FieldSortDescription elements to your XamDataGrid FieldLayout's SortedFields collection. You can read further about doing this here: https://es.infragistics.com/help/wpf/xamdatapresenter-sorting-and-grouping-fields-programmatically.
I have attached a sample project to demonstrate the initial ListCollectionView grouping operation. I hope this helps.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
Hi Andrew,
Thanks for the prompt reply. I'm using the FieldLayout SortedFields collection to add the grouping. But, one thing I noticed is that when I sort on a field, the expanded grid is collapsing. Is there a way to sort without collapsing? can I customize the header display? Can I give styling to the group headers?
Thanks,
I have modified the original sample project I had sent you in an attempt to reproduce the collapsing that you are referring to when sorting, but at the moment, I am unable to reproduce this behavior. Would it be possible for you to please provide some additional information on how your XamDataGrid is set up at the moment so I may mimic it on my end to try to reproduce this issue? It would be very helpful if you can modify the sample project that is attached to this post to reflect the behavior you are seeing or perhaps provide an isolated one of your own.
Regarding the header display for the groups and styling them, you can change the display by extracting the GroupByRecord elements from the Records collection of the XamDataGrid and modifying their Description properties. In doing so, this will modify the text that is shown in the group headers. You can catch when the XamDataGrid has been grouped through the UI by handling the Grouped event of the grid.
In order to style the group headers, I would recommend writing a style for GroupByRecordPresenter. This is the visual element that displays the GroupByRecords. Currently, we use a brush resource to style the Background of these elements, and so if you would like to do so, I would recommend that you define a brush using the following key:
<SolidColorBrush x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type ig:XamDataGrid}, ResourceId=LabelHighlight}" Color="Green"/>
The above will color the GroupByRecordPresenter elements green. Note, there may be other spots that use this brush in the XamDataGrid, and so if you do not wish to style them, I would recommend placing this brush in the Resources section of your GroupByRecordPresenter style.
As mentioned above, I am attaching a sample project to demonstrate the above. At the moment, this does not reproduce the sorting collapse behavior that you are referring to.
The sample that you provided the day before, when you click number to sort, it is collapsing the groups. the behavior is not the same in the new sample that you provided yesterday.
I noticed that the sort behavior is happening only when the GroupEvaluationMode is set to "useCollectionView" and sort on the field that is not used in grouping.
As far as the styling is concerned, thanks for the info but if I want to style the field headers in the groupbyarea section, how to achieve that?
Also, if we want to display only few summary fields only on a particular group and not display on other groups, is that possible? this is for a 4 level hierarchy.
Thank you for the response.
Couple of more things,
I'm trying to disable the grouping only for certain fields and allow grouping for the rest. Can I achieve that?
For summaries, can we display the summary in the group headers, above the field that is used for summary, without the label like "Sum" ?
Thank you for your update on this matter.
The field headers in the group-by-area section are LabelPresenter elements, and so I would recommend that if you wish to style them, you write a style for that element. Note, though, that this LabelPresenter element type is the same element type that is used for the actual Field headers in the rest of the XamDataGrid. If you only wish to style the LabelPresenters that exist in the group-by-area and leave the other headers alone, I would recommend you first write a Style for GroupByAreaMulti and add your LabelPresenter style to the Style.Resources section of this style. This would look like the following:
<Style TargetType="{x:Type igDP:GroupByAreaMulti}"> <Style.Resources> <Style TargetType="{x:Type igDP:LabelPresenter}"> </Style> </Style.Resources></Style>
I have attached a modified version of the sample project I had last sent you to demonstrate the above.
Regarding the collapsing behavior, I have reproduced the behavior in which the groups collapse when sorting. It appears you are correct in that this happens when GroupByEvaluationMode is set to "UseCollectionView", although it appears that SortEvaluationMode needs to have this setting as well. I am also only seeing this behavior when there are multiple group descriptions in the underlying ListCollectionView.
This is unexpected behavior, and as such I have reached out to our engineering staff to examine this further. To ensure it receives attention, I have logged this issue in our internal tracking system with a development ID of 242731. I have also created a private support case for you so that you can track this issue. It has an ID of CAS-187265-G9N4G9 and you can access it at https://es.infragistics.com/my-account/support-activity. I will be sending an update to it shortly with more details on the link to this development issue.