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.
Unfortunately, activation email could not send to your email. Please try again.

Grouping and GroupHeaderTemplate for SfListView?

Thread ID:

Created:

Updated:

Platform:

Replies:

128095 Jan 2,2017 07:07 AM Jan 9,2017 05:04 AM Xamarin.Forms 6
loading
Tags: SfListView
Thomas Klocker
Asked On January 2, 2017 07:07 AM

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


Thomas Klocker
Replied On January 2, 2017 07:28 AM

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

Dinesh Babu Yadav [Syncfusion]
Replied On January 3, 2017 06:43 AM

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 
 
 


Thomas Klocker
Replied On January 5, 2017 02:58 AM

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

Dinesh Babu Yadav [Syncfusion]
Replied On January 6, 2017 08:37 AM

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 
 


Thomas Klocker
Replied On January 6, 2017 01:49 PM

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

Dinesh Babu Yadav [Syncfusion]
Replied On January 9, 2017 05:04 AM

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


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.

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.

;