Skip to content

SyncfusionExamples/How-to-keep-any-one-specific-group-alone-in-the-expanded-state-in-MAUI-DataGrid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

How to keep any one specific group alone in the expanded state in MAUI DataGrid?

The .NET MAUI DataGrid allows you to keep only one group expanded while the remaining groups stay collapsed.

XAML

We wire up the group expanding event in the datagrid.

<syncfusion:SfDataGrid x:Name="dataGrid"
                    x:DataType="local:EmployeeViewModel"
                    AllowGroupExpandCollapse="True"
                    GroupExpanding="dataGrid_GroupExpanding"
                    AutoExpandGroups="False"
                    ItemsSource="{Binding Employees}">

    <syncfusion:SfDataGrid.GroupColumnDescriptions>
        <syncfusion:GroupColumnDescription ColumnName="Title" />
    </syncfusion:SfDataGrid.GroupColumnDescriptions>
</syncfusion:SfDataGrid>

C#

We retrieve the group that is about to expand from the event arguments. We then check whether there is no currently expanded group or if the group to be expanded is different from the currently expanded group. Next, we iterate through all groups in the dataGrid. For each group that is not the one currently expanding, we collapse it. After that, we set the local variable to the group that is currently expanding. Finally, we explicitly expand the group.

private Group? expandedGroup;

private void dataGrid_GroupExpanding(object sender, DataGridColumnGroupChangingEventArgs e)
{
    var group = e.Group;
    if (expandedGroup == null || group!.Key != expandedGroup.Key)
    {
        foreach (Group otherGroup in dataGrid.View!.Groups)
        {
            if (group!.Key != otherGroup.Key)
            {
                dataGrid.CollapseGroup(otherGroup);
            }
        }
        expandedGroup = group!;
        dataGrid.ExpandGroup((Group)expandedGroup!);
    }
}

DataGrid Grouping

View sample in GitHub

Take a moment to pursue this documentation, where you can find more about Syncfusion .NET MAUI DataGrid (SfDataGrid) with code examples. Please refer to this link to learn about the essential features of Syncfusion .NET MAUI DataGrid(SfDataGrid).

Conclusion

I hope you enjoyed learning about how to keep any one specific group alone in the expanded state in MAUI DataGrid.

You can refer to our .NET MAUI DataGrid's feature tour page to know about its other groundbreaking feature representations. You can also explore our .NET MAUI DataGrid Documentation to understand how to present and manipulate data. For current customers, you can check out our .NET MAUI components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our .NET MAUI DataGrid and other .NET MAUI components. If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac or feedback portal. We are always happy to assist you!

About

How to keep any one specific group alone in the expanded state in MAUI DataGrid?

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages