Custom Group Order in SfListView

I have a list of walks with property "Difficulty".

I can successfully group the walks by difficulty, and I have set the group and sort descriptors as to property name "difficulty" with sort order ascending.

This renders the groups in the following order:

Easy
Extreme
Hard
Medium

I'd like the groups to be returned in the following order:
Easy
Medium
Hard
Extreme

I've also created a value converter that represent the difficulty levels as int,  so Easy=1,Medium=2,Hard=3,Extreme=4

I have looked at the documentation for grouping and for group sort descriptors etc but I cannot find a way of calling the value converter in the group sort descriptor  Is there a way to achieve what i'm looking for?

Thanks

1 Reply 1 reply marked as answer

SS SaiGanesh Sakthivel Syncfusion Team April 9, 2021 02:33 AM UTC

Hi Jim,

Thank you for contacting syncfusion support.
 

#Regarding Custom Group Order in SfListView
 
We would like to inform you that you can achieve your requirement with the help of Datasource sort descriptor and Converter in the SfListview. Please refer to the following code snippet for your reference. 
 
Code snippet
Behavior class
 
public class GroupHeaderConverter : IValueConverter 
{ 
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
        if ((int)(value) == 0) 
        { 
            return "Easy"; 
        } 
        else if ((int)(value) == 1) 
        { 
            return "Medium"; 
        } 
        else if ((int)(value) == 2) 
        { 
            return "Hard"; 
        } 
        else 
            return "Extreme"; 
    } 
 
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
        throw new NotImplementedException(); 
    } 
} 
 
Xaml
 
<syncfusion:SfListView x:Name="listView"  
                        ItemSpacing="1"  
                        AutoFitMode="Height"  
                        BackgroundColor="AliceBlue" 
                        ItemsSource="{Binding contactsinfo}"> 
    <syncfusion:SfListView.DataSource> 
        <data:DataSource> 
            <data:DataSource.GroupDescriptors> 
                <data:GroupDescriptor PropertyName="Difficulty"/> 
            </data:DataSource.GroupDescriptors> 
            <data:DataSource.SortDescriptors> 
                <data:SortDescriptor PropertyName="Difficulty" Direction="Ascending"/> 
            </data:DataSource.SortDescriptors> 
        </data:DataSource> 
    </syncfusion:SfListView.DataSource> 
    <syncfusion:SfListView.GroupHeaderTemplate> 
        <DataTemplate > 
            <Grid> 
                <Label x:Name="label" Text="{Binding Key,Converter={StaticResource GroupHeaderConverter}}"  /> 
            </Grid> 
        </DataTemplate> 
    </syncfusion:SfListView.GroupHeaderTemplate> 
 
Please refer to the tested sample in the following link for your reference. 
 
Please let us know if you have any concern.

Regards,
SaiGanesh Sakthivel




Marked as answer
Loader.
Up arrow icon