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,
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.
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,
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.