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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Standard ListView grouping to SfListView grouping?

Thread ID:

Created:

Updated:

Platform:

Replies:

142873 Feb 23,2019 11:14 PM UTC Feb 25,2019 08:57 AM UTC Xamarin.Forms 1
loading
Tags: SfListView
Morten
Asked On February 24, 2019 12:17 PM UTC

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.

Jayaleshwari N [Syncfusion]
Replied On February 25, 2019 08:57 AM UTC

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. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;