SfDataGrid and SfDataPage OnDemandLoading first page is not displayed

When loading a page, the first page is not displayed, switching to the second page loads the data



public partial class OrdersListPage : ContentPage
{
    private OrdersListViewModel vm;
    private SfDataGrid dataGrid;
    private SfDataPager dataPager;
    public OrdersListPage()
    {
        vm = ServiceHelper.GetService<OrdersListViewModel>();
        BindingContext = vm;


        var grid = new Grid
        {
            RowDefinitions = new RowDefinitionCollection
            {
                new RowDefinition(70),
                new RowDefinition(Star),
                new RowDefinition(70)
            }
        };


        dataGrid = new SfDataGrid
        {
            AutoGenerateColumnsMode = AutoGenerateColumnsMode.None,
            RowHeight = 50,
            HorizontalOptions = LayoutOptions.Fill,
            ColumnWidthMode = ColumnWidthMode.Fill,
            Columns = new ColumnCollection
            {
                new DataGridTextColumn
                {
                    MappingName = "OrderId",
                    HeaderText = "№ Заказа",
                    MinimumWidth = 150
                },
                new DataGridTextColumn
                {
                    MappingName = "Status",
                    HeaderText = "Статус",
                    MinimumWidth = 200
                },
                new DataGridTextColumn
                {
                    MappingName = "OrderChanel",
                    HeaderText = "Источник",
                    MinimumWidth = 200
                },
                new DataGridTextColumn
                {
                    MappingName = "PaymentStatus",
                    HeaderText = "Оплата",
                    MinimumWidth = 200
                },
                new DataGridTextColumn
                {
                    MappingName = "DeliveryStatus",
                    HeaderText = "Доставка",
                    MinimumWidth = 200
                },
                new DataGridNumericColumn
                {
                    MappingName = "OrderTotal",
                    HeaderText = "Сумма",
                    MinimumWidth = 200,
                    Format = "#"
                },
                new DataGridCheckBoxColumn
                {
                    MappingName = "CheckIn",
                    HeaderText = "Чек",
                    MinimumWidth = 200
                },
                new DataGridTextColumn
                {
                    MappingName = "CreateDate",
                    HeaderText = "Дата",
                    MinimumWidth = 250
                }
            }
        };


        dataGrid.Row(1);


        dataPager = new SfDataPager
        {
            PageSize = 20,
            PageCount = 10,
            NumericButtonCount = 10,
            UseOnDemandPaging = true
        };
        dataPager.Row(2);


        dataPager.OnDemandLoading += dataPager_OnDemandLoading;


        dataGrid.SetBinding(SfDataGrid.ItemsSourceProperty, new Binding(){Path = "PagedSource", Source = dataPager, Mode = BindingMode.TwoWay});


        grid.Children.Add(dataPager);


        grid.Children.Add(dataGrid);


        Content = grid;
    }


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

9 Replies

NY Nirmalkumar Yuvaraj Syncfusion Team May 6, 2024 06:58 AM UTC

Hi Igor


Based on the provided information, we conducted tests using a simple sample to replicate the reported issues. However, we were unable to reproduce the issues as described. In our sample, we set the DataSource using onDemandPaging, and the DataGrid is functioning properly. The first page loads with data.


We tested this scenario using the attached sample, and it worked correctly without any issues. If you are still encountering the problem, we kindly request that you modify the attached sample to reproduce the issue and provide additional details. This will greatly assist us in further investigating the issue and providing an appropriate solution as quickly as possible.


Regards,

Nirmalkumar


Attachment: SfDataGridSample_7db7b751.zip


IG Igor May 6, 2024 12:19 PM UTC

Hi!


I am getting data asynchronously from the server and the first page is not displayed!


If I remove the asynchrony, at all stages of data retrieval, the data is displayed, but it causes a noticeable slowdown in the application.



NY Nirmalkumar Yuvaraj Syncfusion Team May 7, 2024 01:57 PM UTC

Hi Igor


Based on the information provided, we have prepared a sample that asynchronously sets the datasource to the datapager. However, while testing, both the datapager and datagrid seem to be working fine. I have shared the sample with you for your reference. If you are still encountering the problem, we kindly request that you modify the attached sample to reproduce the issue and provide additional details. This will greatly assist us in further investigating the issue and providing an appropriate solution as quickly as possible.


Regards,

Nirmalkumar


Attachment: SfDataGridSample_1667a2fd.zip


IG Igor May 7, 2024 03:38 PM UTC

Hi!


Your example failed to run, I changed the path to the file, but still got a white screen


I have attached my example

Running under macos system



Attachment: AppStockAndOrdersMAUI_4ada5dac.zip


NY Nirmalkumar Yuvaraj Syncfusion Team May 13, 2024 06:13 AM UTC

Hi Igor


Based on the information provided in the note of the following link , it is not advisable to set the value for the source in the event itself. Please set the value of the source elsewhere and check if the issue persists.


Regards,

Nirmalkumar.



IG Igor May 15, 2024 11:08 AM UTC

Hi


Pagination is not working with asynchrony, I have called in different places the method to get data. The last option I sent, I received the data in an event to make sure it had time to load


If you receive data in the ViewModel constructor, they do not have time to load, the pagination event is triggered and there is an empty collection there



NY Nirmalkumar Yuvaraj Syncfusion Team May 16, 2024 01:46 PM UTC

Hi Igor,


Based on the information provided, the issue you are experiencing is related to the view not refreshing. After loading the data in onDemandPaging, you can use view.Refresh() to refresh the view. We have attached a code snippet for your reference.


Code snippet:

private async void dataPager_OnDemandLoading(object? sender, OnDemandLoadingEventArgs e)

{

    var source = await vm.LoadOrders();

    dataPager.LoadDynamicItems(e.StartIndex, source.Skip(e.StartIndex).Take(e.PageSize));

    dataGrid.View!.Refresh();

}


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Regards,

Nirmalkumar.



IG Igor May 19, 2024 09:54 AM UTC

Hi!


This helps with the display



NY Nirmalkumar Yuvaraj Syncfusion Team May 20, 2024 06:49 AM UTC

Hi Igor


We hope the provided solution resolves the issue on your end. Please get back to us if you need further assistance.


Regards,

Nirmalkumar.


Loader.
Up arrow icon