How to keep the DetailsView of a SfDataGrid expanded?

Hi!

I have a SfDataGrid and I made a DetailsViewDefinition for that. I also make ExpandAllDetailsView from code to expand all details and I want to keep these open, but right after the first reorder or first regroup these will collapse.

I tried kinda every events (what made sense) to reopen, but only the MouseUp was the closest to the goal, but that was kinda bad because it does not work on header and will reopen on every mouseups, so it was a very bad hack.

I would like to know a good and working way to keep the rowdetail open even after events like reorder/group.

Thanks!


3 Replies

SS Susmitha Sundar Syncfusion Team February 20, 2020 07:44 AM UTC

Hi Ponyist, 
 
Thank you for using Syncfusion controls. 

You can achieve your requirement by using SfDataGrid.ExpandAllDetailsView method. For grouping, you can achieve this by SfDataGrid.GroupColumnDescriptions.CollectionChanged event, 

this.dataGrid.GroupColumnDescriptions.CollectionChanged += GroupColumnDescriptions_CollectionChanged; 
 
private void GroupColumnDescriptions_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) 
 { 
     dataGrid.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.ApplicationIdle, 
          new Action(() => 
          { 
              this.dataGrid.ExpandAllDetailsView(); 
          })); 
 } 


For sorting you can achieve this by SfDataGrid.SortColumnsChanged event, 

this.dataGrid.SortColumnsChanged += DataGrid_SortColumnsChanged; 
 
private void DataGrid_SortColumnsChanged(object sender, GridSortColumnsChangedEventArgs e) 
{ 
    dataGrid.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.ApplicationIdle, 
         new Action(() => 
         { 
             this.dataGrid.ExpandAllDetailsView(); 
 
         })); 
} 

 
Please check the sample and let us know if you need further assistance on this. 

Regards, 
Susmitha S 



PP Ponyist Péter replied to Susmitha Sundar February 20, 2020 10:25 PM UTC

Hi Ponyist, 
 
Thank you for using Syncfusion controls. 

You can achieve your requirement by using SfDataGrid.ExpandAllDetailsView method. For grouping, you can achieve this by SfDataGrid.GroupColumnDescriptions.CollectionChanged event, 

this.dataGrid.GroupColumnDescriptions.CollectionChanged += GroupColumnDescriptions_CollectionChanged; 
 
private void GroupColumnDescriptions_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) 
 { 
     dataGrid.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.ApplicationIdle, 
          new Action(() => 
          { 
              this.dataGrid.ExpandAllDetailsView(); 
          })); 
 } 


For sorting you can achieve this by SfDataGrid.SortColumnsChanged event, 

this.dataGrid.SortColumnsChanged += DataGrid_SortColumnsChanged; 
 
private void DataGrid_SortColumnsChanged(object sender, GridSortColumnsChangedEventArgs e) 
{ 
    dataGrid.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.ApplicationIdle, 
         new Action(() => 
         { 
             this.dataGrid.ExpandAllDetailsView(); 
 
         })); 
} 

 
Please check the sample and let us know if you need further assistance on this. 

Regards, 
Susmitha S 


Hi Susmitha!

Thank you for your help, it works.

Have a nice day:
Péter


SS Susmitha Sundar Syncfusion Team February 21, 2020 03:22 AM UTC

Hi Ponyist , 
 
Thanks for the update. 
 
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you. 
 
Regards, 
Susmitha S 


Loader.
Up arrow icon