Collapse Groups by default

Hey,

We are trying to Collapse all Groups in a sfListView by default. To do this, we need call CollapseAll every time the ItemsSource is changing and couldn't find an event to handle this. How can this be done?

Thanks,
Mano

7 Replies

RS Rawoof Sharief Muthuja Sherif Syncfusion Team June 21, 2018 05:42 AM UTC

Hi Mano, 
 
Thanks for contacting Syncfusion support. 
 
We have checked the reported query “Collapse all groups by default” from our end. We would like to let you know that you can achieve your requirement by calling the CollapseAll method in the Loaded event of the SfListView and you need to collapse when ItemsSource changed at run time then you need to hook the property changed event of the SfListView and call collapse all method like below code snippet. 
 
Code Example[C#]: 
public partial class GroupingPage : ContentPage 
    { 
        public GroupingPage() 
        { 
          listView.Loaded += ListView_Loaded; 
          listView.PropertyChanged += ListView_PropertyChanged; 
 
      private void ListView_Loaded(object sender, ListViewLoadedEventArgs e) 
        { 
            listView.CollapseAll(); 
        } 
 
     private void ListView_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) 
        { 
            if(e.PropertyName=="ItemsSource") 
            { 
                listView.CollapseAll(); 
            } 
        } 
 
 
Please let us know if you require further assistance. 
 
Regards, 
Rawoof M. 



MS Mano Sadeh June 21, 2018 07:56 AM UTC

Thanks.

Unfortunately, this approach dos't work.  The PropertyChanged event where "ItemsSource" changed, the Groups are still 0 and calling CollapseAll, not collapsing the Groups.

This is our grouping initializing in the ContentPage constractor:

listView.DataSource.GroupDescriptors.Add(new GroupDescriptor()
            {
                KeySelector = (object obj) =>
                {
                    Data.Feature feature = (obj as Data.Feature);
                    return feature.Attributes["WorkSiteID"];
                }
            });

Thanks,
Mano


RS Rawoof Sharief Muthuja Sherif Syncfusion Team June 22, 2018 06:17 AM UTC

 
Hi Mano, 
 
If you want to collapse all the groups initially when load the listview then you need to call the CollapseAll method in the Loaded event of the SfListView. If you want to collapse all the groups when changing the ItemSource then you need to call the CollpaseAll method in the PropertyChanged event of the SfListView. Also please refer the below documentation for more details about the group expand and  collapse. 
 
 
Please let us know if you require further assistance. 
 
Regards, 
Rawoof M. 



MS Mano Sadeh June 22, 2018 07:31 AM UTC

Thanks.

As is describe in my last replay, this proposed solution doesn't work. 

Thanks,
Mano


RS Rawoof Sharief Muthuja Sherif Syncfusion Team June 25, 2018 11:45 AM UTC

Hi Mano, 
 
Please follow the incident created under your account for further details regarding the reported query. 
 
Regards, 
Rawoof M. 
 
 



AR armin rasoulian December 31, 2018 01:41 PM UTC

This solution is not working for me too.
At the execution time of listView_Loaded event handler, ItemsSource count is 0.
What is the appropriate solution?

Attachment: ScreenShot_bc41c092.rar


JN Jayaleshwari N Syncfusion Team January 2, 2019 12:28 PM UTC

Hi Armin,  
  
Thanks for using Syncfusion product.   
   
We have checked the query by invoking CollapseAll method in Loaded Event from our side. We could able to collapse the groups when CollapseAll called and also get the ItemsSource in loaded event. In given screenshot, ItemsSource displayed as 0, this might happen because of items in collection didn’t populate in the listview initially when loaded. You can either invoke CollapseAll in the thread by setting delay in loaded event like following code or invoke CollaseAll method after all items added into Collection.  
 
private void  ListView_Loaded(object sender, ListViewLoadedEventArgs e)  
{  
   Device.BeginInvokeOnMainThread(async() => {  
   await Task.Delay(1000);  
   ListView.CollapseAll();  
});   
  
We have attached the tested sample along with screenshot for your reference, please find the sample from following link.   
    
Please check the reported issue occurs in our sample also. If the above sample does not meet your requirement could you please modify the above sample to replicate the issue which would highly help us to analyze the query better and provide an appropriate solution.    
  
Regards,  
Jayaleshwari N 


Loader.
Up arrow icon