Grouping and sort the groups from the value in the column and not the group title

I have the following problem:

I have a grouping where as the unterlying data filed for grouping is a date field. The field used for grouping is hiden in the grids view. The column has a format wheres it should only show the year and the month, e.g. 2020 January. If I configure the columns format like that the sorting will be done according to the visible value in the group header.

 But I want to sort the group according the value in the columns data field (date) and not according to the shown value in the group header.

The main problem seems to me, that it is not possible to format a value in the group header text similar to the column (e.g {key:yyyy MMMM})

How can I achive a different value in the group heading but remaining the sorting?

At the moment I added the a sort criteria like <year><month> at the begining to keep the sorting. But this looks not very nice in a report. 

 

Regards,

Brunouary. 

Attachment: 1311_2020_000353_ce3b142d.zip

4 Replies 1 reply marked as answer

CS Chandrasekar Sampathkumar Syncfusion Team November 15, 2020 06:03 PM UTC

Hi Zimmermann, 
Thank you for using Syncfusion products. 
We have checked the reported query “Group and sort the groups from the value in the column and not the group title” from our end. We are currently validating the reported query and update you further details on or before 17th November, 2020. We appreciate your patience until then. 
Chandrasekar Sampathkumar 



GS Gokul Saravanan Syncfusion Team November 17, 2020 07:14 PM UTC

Hi Zimmermann, 
Thank you for your patience. 
We have checked the reported query “Group and sort the groups from the value in the column and not the group title” from our end. We suggest you write the comparer logic to achieve your requirement. Please refer the following code snippet for ore reference. 
Xaml: Add Comparer to DataGrid 
<ContentPage.Resources> 
    <ResourceDictionary> 
        <local:GroupConverter x:Key="groupConverter" /> 
        <local:CustomSortComparer x:Key="sortComparer"/> 
    </ResourceDictionary> 
</ContentPage.Resources> 
 
<sfgrid:SfDataGrid x:Name="sfGrid"  
                AllowSorting="True" 
                ColumnSizer="Star" 
                AllowDraggingRow="True" 
                AllowResizingColumn="True" 
                SelectionMode="Single" 
                AllowEditing="True" 
                NavigationMode="Cell" 
                AllowKeyboardNavigation="True" 
                ItemsSource="{Binding OrdersInfo}"  
                ShowColumnWhenGrouped="False"> 
    <sfgrid:SfDataGrid.GroupColumnDescriptions> 
        <sfgrid:GroupColumnDescription ColumnName="ShipDate" Comparer="{StaticResource sortComparer}" Converter="{StaticResource groupConverter}" /> 
   </sfgrid:SfDataGrid.GroupColumnDescriptions> 
</sfgrid:SfDataGrid> 
 
C#: Comparer logic 
public class CustomSortComparer : IComparer<object>, ISortDirection 
{ 
    public ListSortDirection SortDirection { get; set; } 
    public CustomSortComparer() 
    { 
    } 
 
    public int Compare(object x, object y) 
    { 
        DateTime dateX = DateTime.MaxValue; 
        DateTime dateY = DateTime.MaxValue; 
        if (x.GetType() == typeof(OrderInfo)) 
        { 
            dateX = ((OrderInfo)x).ShipDate; 
            dateY = ((OrderInfo)y).ShipDate; 
        } 
        else if (x.GetType() == typeof(Group)) 
        { 
            dateX = DateTime.ParseExact(((Group)x).Key.ToString(), "yyyy MMMM", CultureInfo.InvariantCulture);  
            dateY = DateTime.ParseExact(((Group)y).Key.ToString(), "yyyy MMMM", CultureInfo.InvariantCulture); 
        } 
        else 
        { 
            dateX = (DateTime)x; 
            dateY = (DateTime)y; 
        } 
 
        if (DateTime.Compare(dateX, dateY) >= 0) 
            return SortDirection == ListSortDirection.Ascending ? 1 : -1; 
        else 
            return SortDirection == ListSortDirection.Ascending ? -1 : 1; 
    } 
} 
 
We have prepared a simple sample based on your requirement and you can download the same using the following link, 
Sample Link: Sample 
Please let us know if you need any further assistance. 
Regards, 
Gokul S 


Marked as answer

ZI Zimmermann December 7, 2020 11:45 AM UTC

Hi 

Many thanks for the proposed solution. With the custom comparer I was able to sort according to the date.

Regards,

Bruno




KK Karthikraja Kalaimani Syncfusion Team December 8, 2020 12:22 PM UTC

Hi Zimmerman,

Thanks for the update. We glad to know that your requirement has been achieved at your end.

Regards,
Karthik Raja

Loader.
Up arrow icon