Articles in this section
Category / Section

How to load pages on demand using async and await in .NET MAUI DataGrid (SfDataGrid) ?

3 mins read

In this article, we will demonstrate how to load pages on demand using async and await in the .NET MAUI DataGrid.

xaml

<ContentPage.BindingContext>
    <local:OrderInfoViewModel x:Name="vm" />
</ContentPage.BindingContext>

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="70" />
        <RowDefinition Height="*" />
        <RowDefinition Height="70" />
    </Grid.RowDefinitions>

    <syncfusionControls:SfDataPager x:Name="dataPager"
                                    PageSize="20"
                                    PageCount="10"
                                    NumericButtonCount="10"
                                    UseOnDemandPaging="True"
                                    Grid.Row="2"
                                    OnDemandLoading="dataPager_OnDemandLoading" />

    <syncfusion:SfDataGrid x:Name="dataGrid"
                            HorizontalOptions="Fill"
                            ColumnWidthMode="Fill"
                            Grid.Row="1"
                            ItemsSource="{Binding PagedSource, Source={x:Reference dataPager}, Mode=TwoWay}" />
</Grid>

C#
The code below illustrates how to load pages on demand using async and await in the DataGrid.

private async void dataPager_OnDemandLoading(object? sender, OnDemandLoadingEventArgs e)
{
    var sourse = await vm.orderData.GetOrdersAsync(); 
    dataPager.LoadDynamicItems(e.StartIndex, sourse.Skip(e.StartIndex).Take(e.PageSize));
    (dataPager.PagedSource as PagedCollectionView).ResetCache();
}

Please remember to change the path according to your device’s location when setting the connection string.

Output

asyncScreenShot.png

Download the complete sample from GitHub.

Conclusion

I hope you enjoyed learning how to load pages on demand using async and await in .NET MAUI DataGrid (SfDataGrid).

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 on the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to explore 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 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