We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Paging LoadDynamicItems not work

Hi all,

Who can help me fix this problem.
This is my code for using SfDataGrid with UseOnDemandPaging.


using Syncfusion.SfDataGrid.XForms;
using Syncfusion.SfDataGrid.XForms.DataPager;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace HelloSyncfusion
{
    public partial class MainPage : ContentPage
    {
        SfDataGrid sfGrid = new SfDataGrid();

        SfDataPager sfDataPager = new SfDataPager();

        StackLayout parent = null;
        VE_VESSEL_INFO_Repository resposity = new VE_VESSEL_INFO_Repository();
        public MainPage()
        {
            InitializeComponent();

            
            //sfGrid.ItemsSource = new OrderInfoRepository().OrderInfoCollection;  //Setting ItemsSource to SfDataGrid
            sfGrid.ColumnSizer = ColumnSizer.Star;

            Grid myGrid = new Grid();
            myGrid.HorizontalOptions = LayoutOptions.FillAndExpand;

            myGrid.RowDefinitions = new RowDefinitionCollection
            {
              new RowDefinition { Height = 50 },
              new RowDefinition {},
            };

            
            sfDataPager.OnDemandLoading += SfDataPager_OnDemandLoadingAsync;
            sfDataPager.UseOnDemandPaging = true;

            sfDataPager.PageSize = 5;
           
            sfGrid.ItemsSource = sfDataPager.PagedSource;

            myGrid.Children.Add(sfDataPager, 0, 0);
            myGrid.Children.Add(sfGrid, 0, 1);
            this.Content = myGrid;
            
        }

        private async void SfDataPager_OnDemandLoadingAsync(object sender, OnDemandLoadingEventArgs args)
        {
            //throw new NotImplementedException();
            var vesseles = await resposity.GetCollection(); //List<object> --> Debug: OK, list count = 12
               
            sfDataPager.LoadDynamicItems(args.StartIndex,vesseles.Skip(args.StartIndex).Take(args.PageSize));
            sfDataPager.PagedSource.Refresh();
            
        }
        
    }
}

But result don't show data, and paging as attached image
https://drive.google.com/file/d/0B-4vIZrlaPNzbnVHMDc0blJyZTQ/view



7 Replies

AN Ashok N Syncfusion Team July 10, 2017 09:58 AM UTC

Hi Michael, 
 
Thanks for contacting Syncfusion support. 
 
We have checked your code snippet and you didn’t bind the SfDataGrid.ItemsSource , instead of you are set the SfDataPager.PagedSource is ItemsSource of SfDataGrid. For OnDemandLoading initially PagedSource was null, and based on the PagedSource only we are setting the ItemsSource to SfDataGrid in Paging. You can achieve your requirement by Binding PagedSource as ItemsSource to SfDataGrid. Please refer the below Code example:  
 
public partial class SfDataGridPage : ContentPage 
{ 
    private OrderInfoRepository repository; 
    private ObservableCollection<OrderInfo> source; 
    public SfDataGridPage() 
    { 
        InitializeComponent(); 
        repository = new OrderInfoRepository(); 
        source = repository.GetOrderDetails(200); 
        this.dataPager.OnDemandLoading += DataPager_OnDemandLoading; 
        this.dataGrid.SetBinding(SfDataGrid.ItemsSourceProperty, new Binding() { Path = "PagedSource", Source = this.dataPager }); 
    } 
 
    private void DataPager_OnDemandLoading(object sender, OnDemandLoadingEventArgs args) 
    { 
        dataPager.LoadDynamicItems(args.StartIndex, viewModel.OrdersInfo.Skip(args.StartIndex).Take(args.PageSize)); 
    } 
} 
 
Please refer the below Sample for more reference , 
 
 
Regards, 
Ashok 



JC Juan Camilo October 6, 2018 05:31 PM UTC

Hi,

I'm trying to binding the property to ItemsSource property of SfDataGrid:



And trying to update the data through a Message/Subscriber:



Unfortunately, nothing of that worked for me. I know that the Subscriber is working because I see the Console message, but I don't understand why the ItemsSource don't update with the new data.

I really appreciate some help.

Thanks



Attachment: bindingerrorpaging_f10edb75.zip


VR Vigneshkumar Ramasamy Syncfusion Team October 8, 2018 12:17 PM UTC

Hi Michael,  
  
Thanks for contacting Syncfusion support.   
  
We have analyzed your query with the provided code snippet. In that you have set “ItemsSource” for “SfDataGrid” but you have missed to set the “Source” property to “SfDataPager”. We need to set the “Source” property to “SfDataPager”. We have prepared the sample for your reference, you can download the same from the below link.  
  
Also refer the below UG link.  
 
 
Please let us know if this helpful.  
 
Regards,  
Vigneshkumar R 



JC Juan Camilo October 9, 2018 11:43 PM UTC

Hi Vigneshkumar R,

Thanks for your answer. Unfortunately, I don't use the Normal Paging, instead, I use OnDemandPaging (https://help.syncfusion.com/xamarin/sfdatagrid/paging?cs-save-lang=1&cs-lang=csharp#ondemandpaging). For that reason I don´t set Source property of SfDataPager:



The way that I use OnDemanndPaging is as follows:

1. Create a Behavior, that is attached to OnDemandLoading event, and call to a Command defined in ViewModel. The way that I create the behavior is the same that Microsoft defines in his ebook Enterprise Patterns (ebook link: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/enterprise-application-patterns/mvvm#invoking-behaviors-from-a-view, source code of Behavior: https://github.com/dotnet-architecture/eShopOnContainers/blob/master/src/Mobile/eShopOnContainers/eShopOnContainers.Core/Behaviors/EventToCommandBehavior.cs)



2. In the command, I call a local method of the ViewModel, and there, I show a console message and call Send Method (Subscriber Pattern, https://docs.microsoft.com/en-us/xamarin/xamarin-forms/enterprise-application-patterns/communicating-between-loosely-coupled-components#publishing-a-message):





3. In the code behind, I subscribe to the Event, and then receive the DataSource. But, this is the part where I cannot update the View showing the data (using the API as suggested in the documentation):



This is as suggested:



I don't know what's wrong with my code, or if need to call an adittional method that take the updated datasource and update the view.

Thanks again!!



VR Vigneshkumar Ramasamy Syncfusion Team October 11, 2018 07:21 AM UTC

Hi Michael,  
  
Thanks for using Syncfusion support.  
  
We have analyzed your query and the provided code snippet. In that, you have missed to set the PageCount property to DataPager. We need to set PageCount property for SfDataPager. I have prepared the sample for your requirement and attached for your reference. You can download the same from the below link.  
  
 
Please let us know if this helpful.  
 
Regards,  
Vigneshkumar R 



JC Juan Camilo October 12, 2018 12:44 AM UTC

Thank you Vigneshkumar, it was that parameter, it works!


VR Vigneshkumar Ramasamy Syncfusion Team October 12, 2018 07:29 AM UTC

Hi Michael,   
 
We glad to know that your requirement has been achieved. Please get in touch if you required further assistance on this. 
   
Regards 
Vigneshkumar R 


Loader.
Live Chat Icon For mobile
Up arrow icon