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
close icon

How can I disable grouping in SfDataGrid

I want to toggle grouping in SfDataGrid on an off.

Is there something better?
This code makes the columns to resize, in some cases to width = 0.

if (Grid.GroupColumnDescriptions.Count > 0)

{

   Grid.GroupColumnDescriptions.Clear();

}

else

{

   foreach (var droupDescription in listPropertyGroupDescription)

   {

                        var group = new GroupColumnDescription()

                        {

                            ColumnName = droupDescription.PropertyName

                        };

                       

                        Grid.GroupColumnDescriptions.Add(group);

   }

}


1 Reply

JG Jai Ganesh S Syncfusion Team April 1, 2015 06:32 PM UTC

Hi Andreas,

 

Thank you for using Syncfusion products.

 

We have analyzed your query and we need more information on your requirement. Based on your title, you can disable the grouping by set AllowGrouping as false. If you would like to add and remove the groups at runtime like toggle the group on or off on specific column by below code snippet,

 

Code Snippet [C#]:

 

private void Button_Click(object sender, RoutedEventArgs e)

 {

                     if (sfdatagrid.GroupColumnDescriptions.Any())

                            sfdatagrid.GroupColumnDescriptions.Clear();

                    else

                            sfdatagrid.GroupColumnDescriptions.Add(new GroupColumnDescription() { ColumnName = "ProductName" });

  }

 

 

We have also prepared the sample based on this and please find the sample under the following location,

 

Sample Link: http://www.syncfusion.com/downloads/support/directtrac/136396/SfDataGroupingDemo-553868901.zip

 

If we misunderstood your requirement, could you please let us know, what you are trying to achieve from your code snippet and in which case column width will be 0. Please share the more details about your query. This would be more helpful for us to serve you in better way.

 

Please let us know if you need further assistance.

 

Thank you,

Jai Ganesh S


Loader.
Live Chat Icon For mobile
Up arrow icon