Articles in this section
Category / Section

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

3 mins read

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

C#
In behavior class, set the ViewModel.IsLoading property value to true and false based on items generation using the 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 the ViewModel.IsLoading property to SfBusyIndicator.IsRunning property to enable or disable the busy indicator in the view until items are 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>
Output


show a SfBusyIndicator while loading Data in DataGrid


Download the complete sample from GitHub.

Conclusion

I hope you enjoyed learning how to show a busy Indicator while loading data in .NET MAUI DataGrid.

You can refer to our .NET MAUI DataGrid feature tour page to learn about its other groundbreaking feature representations. Explore our .NET MAUI DataGrid Documentation to understand how to present and manipulate data.

For current customers, check out our .NET MAUI components from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our .NET MAUI DataGrid and other .NET MAUI components.

Please let us know in the comments section if you have any queries or require clarification. 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