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

Show a group header without any child views.

Hi There,

When using grouping in a ListView is there a way to create a header for a group which has no items in the ItemsSource.  I have a button on my header for the user to create items and i need this to be visible when there are 0 items of a particular type.

I thought a hacky way to do it would be to create a default list item for each group i need displayed and have the item height set to 0.

Is there any way manually add a group so that the header can be displayed even if there are no children in the items source?

Many Thanks,
Robbie

3 Replies

DB Dinesh Babu Yadav Syncfusion Team March 3, 2017 03:36 PM UTC

Hi Robbie, 
  
Thank you for using Syncfusion products. 
  
In SfListView, we have grouped the items based on the underlying data bind to ItemsSource property and this is the actual behavior of SfListView. So in order to achieve your requirement “Displaying group headers only without items”, we have an workaround in the sample level with changing ItemsSize property at runtime. By defining the ItemsSize as “0” which you have stated and collapse all the groups using CollapseAll method while initializing the SfListView and therefore the group header items are only visible. And by customizing the GroupHeaderTemplate, you can add the items by tapping on the customized group header template and after the item is added change the ItemsSize. For your reference, we have attached the sample and you can download the same from the below link. 
  
  
In the sample, we have collapsed all the groups and customized the group header template with the header label and an image(Create.png) and defined the ItemsSize as “0”. On tapping the "Create" image, an alert will be displayed in which you can add the item as per your requirement. 
  
Please let us know if you require further assistance. 
  
Regards, 
Dinesh Babu Yadav 



RP Robbie Philips March 16, 2017 11:08 AM UTC

Hi Dinesh,

Thanks for you response and suggestion, I have been able to get it working in my app using a similar approach to yours.

Thanks Again,
Robbie


DB Dinesh Babu Yadav Syncfusion Team March 17, 2017 06:08 AM UTC

Hi Robbie, 
 
Thanks for the update. 
 
Regards, 
Dinesh Babu Yadav 


Loader.
Up arrow icon