This is a migrated thread and some comments may be shown as answers.

Group Order

4 Answers 250 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Joshua
Top achievements
Rank 2
Joshua asked on 08 Apr 2020, 05:54 AM

How can I specify the order in which groups are displayed in the RadListView? The control is automatically sorting my groups alphabetically (regardless of the order in which my items of a specific group are added to my collection), which I really don't want. In fact, my goal is to always have the groups in a specific order that cannot be re-ordered, and I want to specify this order explicitly. That is, it's not an ascending or descending order, but an arbitrary one that I specify.

Here's my XAML:

<telerikDataControls:RadListView x:Name="listView" ItemsSource="{Binding Path=Items}" ItemTemplateSelector="{StaticResource Key=itemDataSelector}" GroupHeaderTemplate="{StaticResource Key=headersTemplate}">
    <telerikDataControls:RadListView.GroupDescriptors>
        <telerikListView:PropertyGroupDescriptor PropertyName="Name"/>
    </telerikDataControls:RadListView.GroupDescriptors>
    <telerikDataControls:RadListView.HeaderTemplate>
        <DataTemplate>
            <Label Text="..."
                    FontSize="Title"
                    FontAttributes="Bold"
                    HorizontalOptions="Fill"
                    HorizontalTextAlignment="Center" />
        </DataTemplate>
    </telerikDataControls:RadListView.HeaderTemplate>
    <telerikDataControls:RadListView.FooterTemplate>
        <DataTemplate>
            <Label Text="..."                       
                    HorizontalOptions="Fill"
                    HorizontalTextAlignment="Center"/>
        </DataTemplate>
    </telerikDataControls:RadListView.FooterTemplate>
</telerikDataControls:RadListView>

 

I'm using Telerik UI for Xamarin 2020.1.218.1, Xamarin Forms 4.5.0.530.

4 Answers, 1 is accepted

Sort by
1
Accepted
Didi
Telerik team
answered on 08 Apr 2020, 01:49 PM

Hi Joshua,

Thank you for the provided code.

The RadListView Grouping is alphabetically by default. In order to achieve non-alphabetically scenario you should use DelegateGroupDescripor and Converter. Please take a look at the attached project how the converter could be implemented. Note that it is up to you how the custom logic will be structured.

I hope the provided sample will help you get started with the scenario you want to achieve.

Regards,
Didi
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Joshua
Top achievements
Rank 2
answered on 08 Apr 2020, 04:36 PM

Hi Didi,

I was able to achieve custom sorting by providing a numeric key and using a ValueConverter in my binding to generate the headings (Label.Text) in my GroupHeaderTemplate, thank you for the suggestion and the example. I did not need to use a DelegateGroupDescriptor as I'm just grouping based off of the value of a single property (the Id of the group).

Regards,

Josh

0
Paul Ridden
Top achievements
Rank 1
Veteran
answered on 26 Jun 2020, 09:42 AM

Hi,

Is it possible to group by one property and then order on another?

I have groups of items which are for the same location however those groups then need to be in a certain order based on another property. Is this possible?

Kind regards,

Paul

0
Paul Ridden
Top achievements
Rank 1
Veteran
answered on 26 Jun 2020, 01:02 PM
I believe I have now implemented what I required, based on the sample posted above.
Tags
ListView
Asked by
Joshua
Top achievements
Rank 2
Answers by
Didi
Telerik team
Joshua
Top achievements
Rank 2
Paul Ridden
Top achievements
Rank 1
Veteran
Share this question
or