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

Grouping and GroupHeaderTemplate for SfListView?

Hi syncfusion-Gurus!

I´m currently using the SfListView in my Xamarin Forms project, and i love the control!
The only thing which i´m missing is the ability to use the IsGroupingEnabled and GroupDisplayBinding properties, like they exist on the 'standard' ListView for xamarin forms.
Is there a way to use this feature also with the SfListView?

Thank you very much for your help!
Greetings

Thomas


6 Replies

TK Thomas Klocker January 2, 2017 12:28 PM UTC

Just for the case you misunderstand me: i know that there is the ability to group via the DataSource.GroupDescriptors, but my problem is that i have a Collection of already "grouped" items. It looks something like this:

public class DeficiencyText
{
     public String Text { get; set; }
}
public class DeficiencyTextGroup : ObservableCollection<DeficiencyText>
{
public DeficiencyText Caption { get; set; }
}

Now i have a ObservableCollection<DeficiencyTextGroup> TextGroups; and this is set to the ListView´s ItemsSource property.
This looks like:

<ListView ItemsSource="{Binding TextGroups}"
IsGroupingEnabled="true"
GroupDisplayBinding="{Binding Caption.Text}">
<!-- header / caption of texts -->
<ListView.GroupHeaderTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout Margin="0,5,0,0">
<Label Text="{Binding Caption.Text}" Margin="5,15,5,15" />
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.GroupHeaderTemplate>

<!-- deficiency text -->
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Text="{Binding Text}" LineBreakMode="WordWrap" Margin="5,1,5,1" />
</Grid>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>


Maybe this is also possible with the SfListView?
Thanks again

Greetings
Thomas


DB Dinesh Babu Yadav Syncfusion Team January 3, 2017 11:43 AM UTC

Hi Thomas, 
 
Thank you for contacting Syncfusion Support. 
 
Currently SfListView does not have support for “IsGroupingEnabled” and “GroupDisplayBinding” properties. Since, we have used the DataSource(non UI component) inside the ListView , the groups are created based on the number of group descriptors added. To disable the groups you can clear the “GroupDescriptors” property. 
 
CodeSnippet[C#] 
listView.DataSource.GroupDescriptors.Clear(); 
 
However, you can achieve your requirement by setting the property to be grouped which contains the collections to the PropertyName of GroupDescriptor and added into the GroupDescriptors. 
 
CodeSnippet[C#] 
listView.DataSource.GroupDescriptors.Add(new GroupDescriptor() 
{ 
PropertyName = "Caption.ContactName", 
KeySelector = (object obj1) => 
{ 
var item = (obj1 as ContactsViewModel); 
return item.Caption.ContactName[0].ToString(); 
}, 
}); 
 
 
For your reference we have attached the sample. Please find the sample link below  
  
  
Please let us know if you need any further assistance.    
 
Regards, 
Dinesh Babu Yadav 
 
 



TK Thomas Klocker January 5, 2017 07:58 AM UTC

Hi Dinesh,

thanks for your help! I tried to implement it in our code, but i couldn´t get it going. Attached you find a sample with our objects.
Is it possible that you could modify this sample so that it will work? That would be awesome!

Also another question: you set the BackgroundColor of the Stacklayout, is it possible to have this set via DataBinding to the Caption.BackgroundColor property?

Thank you very much for your help!
Greetings

Thomas

Attachment: GroupingDeficiencyTexts_a58cb0af.rar


DB Dinesh Babu Yadav Syncfusion Team January 6, 2017 01:37 PM UTC

Hi Thomas, 
 
Sorry for the inconvenience.  
 
SfListView does not have support to bind the ItemsSource like your nested collections. But If your requirement is to display the items in a group, then you can achieve by using GroupDescriptors property. And so we have modified your nested collection and bind it in SfListView to look similar view. Please find the modified sample from below location. 
 
 
For more information, refer the UG link 
 
 
Please let us know if you require any further assistance. 
 
Regards, 
Dinesh Babu Yadav 
 



TK Thomas Klocker January 6, 2017 06:49 PM UTC

Hi Dinesh,

many thanks for your help! I have modified your sample a little bit, now it meets our requirements pretty good. We just have to modify our Model a little bit, then it will work.
I have attached the modified sample, in case someone else is interested and needs something similar.

Greetings
Thomas


Attachment: GroupingDeficiencyTexts_d407681c.rar


DB Dinesh Babu Yadav Syncfusion Team January 9, 2017 10:04 AM UTC

Hi Thomas, 
 
Thanks for the update. 
 
Please let us know if you require any further assistance. 
 
Regards, 
Dinesh Babu Yadav 


Loader.
Up arrow icon