Articles in this section
Category / Section

How to Reset Sorting and Grouping in .NET MAUI DataGrid?

4 mins read

This article shows how to reset sorting and grouping in Syncfusion .NET MAUI DataGrid (SfDataGrid). It demonstrates how a user can cancel sorting and return to its original state programmatically. Similarly, grouping can also be reset programmatically.

Xaml

<ContentPage.BindingContext>
    <local:ViewModel  />
</ContentPage.BindingContext>
<Grid ColumnDefinitions="*,200" ColumnSpacing="5" Padding="10">
    <VerticalStackLayout HorizontalOptions="Center" Grid.Column="1" VerticalOptions="Center" Spacing="10">
        <Button Text="Allow Sorting"
                Clicked="Button_Clicked"
                WidthRequest="150"/>
        <Button Text="Clear Sorting"
                Clicked="Button_Clicked_1"
                WidthRequest="150"/>
        <Button Text="Allow Grouping"
                Clicked="Button_Clicked_2"
                WidthRequest="150"/>
        <Button Text="Clear Grouping"
                Clicked="Button_Clicked_3"
                WidthRequest="150"/>
    </VerticalStackLayout>
    <syncfusion:SfDataGrid x:Name="datagrid"
                           Grid.Column="0"
                           ColumnWidthMode="Fill"
                           ItemsSource="{Binding OrderList}">
        <syncfusion:SfDataGrid.Columns>
            <syncfusion:DataGridNumericColumn MappingName="OrderID" HeaderText="Order ID"/>
            <syncfusion:DataGridTextColumn MappingName="CustomerID" HeaderText="Customer ID"/>
            <syncfusion:DataGridDateColumn MappingName="ShippingDate" HeaderText="Order Date"/>
            <syncfusion:DataGridNumericColumn MappingName="SupplierID" HeaderText="Supplier ID"/>
            <syncfusion:DataGridTextColumn MappingName="ShipCity" HeaderText="Shipping City"/>
            <syncfusion:DataGridTextColumn MappingName="ShipCountry" HeaderText="Shipping Country"/>
            <syncfusion:DataGridNumericColumn MappingName="Freight" HeaderText="Freight"/>
        </syncfusion:SfDataGrid.Columns>
    </syncfusion:SfDataGrid>
</Grid>
</ContentPage.Content>

Xaml.cs

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();
    }

    private void Button_Clicked(object sender, EventArgs e)
    {
        datagrid.SortingMode = Syncfusion.Maui.DataGrid.DataGridSortingMode.Multiple;
    }

    private void Button_Clicked_1(object sender, EventArgs e)
    {
        datagrid.SortColumnDescriptions.Clear();
    }

    private void Button_Clicked_2(object sender, EventArgs e)
    {
        datagrid.GroupingMode = Syncfusion.Maui.DataGrid.GroupingMode.Multiple;
        datagrid.GroupColumnDescriptions.Add(new GroupColumnDescription()
        {
            ColumnName = "ShipCountry",
        });
        datagrid.GroupColumnDescriptions.Add(new GroupColumnDescription()
        {
            ColumnName = "ShipCity",
        });
    }

    private void Button_Clicked_3(object sender, EventArgs e)
    {
        datagrid.GroupColumnDescriptions.Clear();
    }
}

ScreenShot

Here is the expected output when executing the sample:

Sorting

Grouping

View sample in GitHub

Take a moment to explore this documentation, where you can find more information 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 implement select all checkbox column in SfDataGrid.

You can refer to our .NET MAUI DataGrid’s feature tour page to learn 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 on the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to explore our .NET MAUI DataGrid and other .NET MAUI components.

If you have any queries or require clarifications, please let us know in the comments below. You can also contact us through our support forums,Direct-Trac or feedback portal, or the feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied