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));
}
}
xml version="1.0" encoding="UTF-8"?>
<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.