We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Standard ListView grouping to SfListView grouping?

Hey.

I'm trying to convert my application to go from the standard ListView to the SfListView, which has been pretty easy and a good experience up until this point, but I'm having a hard time trying to comprehend how the grouping works in the SfListView compared to the standard ListView, even after thoroughly reading the documentation, as the SfListView grouping implementation sadly seems quite a lot different from the standard ListView.

This is a simplified barebones version of my old grouping implementation using the standard ListView:

Models

public class FineGroup : ObservableCollection<Fine>
{

    public string Status { get; set; }

}  

public class Fine
{

    public string Name { get; set; }
    public decimal Price { get; set; }
    public string Description { get; set; }
    public DateTime Date { get; set; }
    public DateTime? PayDate { get; set; }

}  

ViewModel

public class FinesViewModel
{

    public FinesViewModel()
    {

        this.GroupFines();

    }

    public ObservableCollection<FineGroup> GroupedFinesList = new ObservableCollection<FineGroup>();

    public void GroupFines()
    {

        var FinesList = FineRepository.FineList;

        FineGroup PendingGroup = new FineGroup()
        {
            Status = "Pending"
        };
        this.GroupedFinesList.Add(PendingGroup);
        PendingGroup.AddRange(FinesList.Where(x => x.PayDate == null));

        FineGroup CompletedGroup = new FineGroup()
        {
            Status = "Completed"
        };
        this.GroupedFinesList.Add(CompletedGroup);
        CompletedGroup.AddRange(FinesList.Where(x => x.PayDate != null));

    }

}  

View

xml version="1.0" encoding="UTF-8"?>  
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="App.Views.Fines">
    
    <StackLayout>
            
        <ListView ItemsSource="{Binding GroupedFinesList}" IsGroupingEnabled="true">
            <ListView.GroupHeaderTemplate>
                <DataTemplate>
                    <ViewCell>
                        
                        <Label Text="{Binding Status}"/>
                        
                    ViewCell>
                DataTemplate>
            <ListView.GroupHeaderTemplate>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        
                        <Label Text="{Binding Name}"/>
                        <Label Text="{Binding Price}"/>
                        <Label Text="{Binding Description}"/>
                        <Label Text="{Binding Date}"/>
                        
                    ViewCell>
                DataTemplate>
            ListView.ItemTemplate>
        ListView>
        
    StackLayout>
    
ContentPage>  

This will take my complete list of fines from my FineRepository and apply some logic to determine which fines have been paid and which haven't and then split them into a "Pending" and "Completed" group, which will both be stored in my GroupedFinesList, which will be used as the ItemsSource for my ListView to create my grouped ListView.

How do I achieve the same thing using the SfListView?

EDIT: For some reason the editor keeps removing the first 2 characters on some of the tags in the View portion of this post.

1 Reply

JN Jayaleshwari N Syncfusion Team February 25, 2019 12:57 AM

Hi Morten, 
 
Thanks for contacting Syncfusion Support. 
 
We have checked the reported query “Standard ListView grouping to SfListView grouping?” from our side. We would like to let you know that SfListView has inbuilt support to group the data based on the model property using  DataSource(non UI component). The groups will be created based on the number of group descriptors added to “GroupDescriptors” property. We regret to let you know that the predefined group in ItemsSource is not supported with SfListView as like you done with Xamarin.Forms ListView. 
 
You can refer the following user guide documentation to know about the grouping in SfListView. 
 
The similar requirement has been achieved using SfListView and you can refer from the following link 
 
Please let us know if you would require further assistance. 
 
Regards, 
Jayaleshwari N. 


Loader.
Live Chat Icon For mobile
Up arrow icon