Articles in this section
Category / Section

How to show Busy Indicator while loading data in MAUI DataGrid?

3 mins read

The .NET MAUI DataGrid(SfDataGrid) allows you to show a SfBusyIndicator while loading Data in DataGrid. The busy indicator can be enabled and disabled by using IsRunning property.

C#
In behavior class set ViewModel.IsLoading property value to true and false based items generation using loaded event.

public class MainPageBehavior : Behavior<ContentPage>
{
        SfDataGrid dataGrid;
        ViewModel viewModel;
        protected override void OnAttachedTo(ContentPage bindable)
        {
            base.OnAttachedTo(bindable);
            dataGrid = bindable.FindByName<SfDataGrid>("dataGrid");
            viewModel = (ViewModel)bindable.BindingContext;
            dataGrid.Loaded += DataGrid_Loaded;
        }
 
        private async void DataGrid_Loaded(object sender, EventArgs e)
        {
            this.viewModel.IsLoading = true;
            await Task.Delay(6000);
            this.viewModel.GenerateOrders();
            this.viewModel.IsLoading = false;
        }
 
        protected override void OnDetachingFrom(ContentPage bindable)
        {
            base.OnDetachingFrom(bindable);
            dataGrid = null;
            viewModel = null;
            dataGrid.Loaded -= DataGrid_Loaded;
        }
}

XAML
Bind the value of ViewModel.IsLoading property to SfBusyIndicator.IsRunning property to enable or disable busy indicator into the view until items loaded in the view.

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:core="clr-namespace:Syncfusion.Maui.Core;assembly=Syncfusion.Maui.Core"
             xmlns:local="clr-namespace:DataGridMAUI"
             xmlns:sfDatagrid="clr-namespace:Syncfusion.Maui.DataGrid;assembly=Syncfusion.Maui.DataGrid"
             x:Class="DataGridMAUI.MainPage">
    <ContentPage.BindingContext>
        <local:ViewModel x:Name="ViewModel"></local:ViewModel>
    </ContentPage.BindingContext>
    <ContentPage.Behaviors>
        <local:MainPageBehavior></local:MainPageBehavior>
    </ContentPage.Behaviors>
    <Grid x:Name="grid">
        <sfDatagrid:SfDataGrid x:Name="dataGrid" ColumnWidthMode="Fill" GridLinesVisibility="Both" HeaderGridLinesVisibility="Both" ItemsSource="{Binding OrderInfoCollection}">
        </sfDatagrid:SfDataGrid>
        <core:SfBusyIndicator x:Name="busyIndicator" AnimationType="SingleCircle" IsRunning="{Binding IsLoading,Mode=TwoWay}" TextColor="Magenta"
                                       SizeFactor="0.5"/>
    </Grid> 
</ContentPage>


show a SfBusyIndicator while loading Data in DataGrid


View Sample on Github

Take a moment to pursue this documentation, where you will 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 perform CRUD operations in MAUI DataGrid (SfDataGrid).

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 forumsDirect-Trac or 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