Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
250
How to customize grouping in the XamDataGrid object?
posted

I'm using grouping, which is awesome. However, I noticed that some fields (e.g. DateTime typed) are not grouped by the values (which probably is wise as most of the instances are different, if only my milliseconds, which would create a humongous bunch of groups). However, I'd like to get familiar with how to customize the generated groups. Hence - I have three-tier question.

1. How can I customize the default text of groupings for DateTime typed fields? I.e., I want the three categories to be called something different than what it's by default.

2. How can I declare my own partition for such a field? I.e. I want to split them into "this week", "last quarter", "darn long ago" and "way in the future".

3. How can I create a dynamic grouping not needing to declare the splits explicitly? E.g. making each date belong to a certain month so that grouping will result in all May 2013 to be in the same group, all June 2017 in one etc.

  • 34810
    Verified Answer
    Offline posted

    Hello Konrad,

    Thank you for your post!

    The visual element that you are seeing in the XamDataGrid after grouping is called a GroupByRecordPresenter. This element presents the group by records in the XamDataGrid, and these group by records have a Description property which is used to display the default text groupings. By writing an implicit style for GroupByRecordPresenter, you can use an EventSetter to hook into the Loaded event for these presenters. Then, you can utilize the GroupByRecordPresenter.Record property to get the GroupByRecord that it corresponds to, and set the Description property on this record to your custom text. This is how you can achieve your first point in your original description.

    For your second and third points, you will need to define your own group by evaluator. Essentially, you will need to create your own class that derives from the IGroupByEvaluator interface and also create your own IComparer to determine how to group your records, then set your IGroupByEvaluator on the FieldSettings.GroupByEvaluator property of the fields that you wish to have a customized grouping operation performed on. You can read more about this here: http://help.infragistics.com/Help/Doc/WPF/2013.1/CLR4.0/html/xamDataGrid_Grouping_Overview.html.

    I have also attached a sample project to demonstrate the two procedures I have described above. The attached sample has a data source with dates from three separate months, and uses the IGroupByEvaluator to group them by month. It also demonstrates the usage of the GroupByRecordPresenter style mentioned above. I hope this helps you.

    Please let me know if you have any other questions or concerns on this matter.

    Sincerely,
    Andrew
    Associate Developer
    Infragistics Inc.
    www.infragistics.com/support

    XDGGroupByCase.zip