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.
Unfortunately, activation email could not send to your email. Please try again.

Binding to an asynchronous REST service

Thread ID:

Created:

Updated:

Platform:

Replies:

124002 May 7,2016 03:53 AM May 19,2016 06:59 AM Xamarin.Forms 6
loading
Tags: SfDataGrid
Paul
Asked On May 7, 2016 03:53 AM

I am using a Xamarin Forms SfDataGrid and I want to call a REST service asynchronously and bind the data returned to the SfDataGrid.

       <syncfusion:SfDataGrid x:Name="dgPortfolios" Grid.Column="0" Grid.Row="1" ItemsSource="{Binding Portfolios}"
                               VerticalOptions="FillAndExpand" ColumnSizer="Star" AllowSorting="True">
           
            <syncfusion:SfDataGrid.BindingContext>
                <local:PortfolioViewModel />
            </syncfusion:SfDataGrid.BindingContext>

        </syncfusion:SfDataGrid>

 public class PortfolioViewModel
    {
        ITradingService _tradingService;

        public ObservableCollection<PortfolioPerformance> Portfolios { get; set; }
 
        public PortfolioViewModel()
        {
            Load();
        }

        public async void Load()
        {
            var http = new HttpClient(new NativeMessageHandler());
            http.BaseAddress = new Uri(AppConstants.TradingServiceURL);
            _tradingService = Refit.RestService.For<ITradingService>(http);

           var portfolios = await _tradingService.SearchPortfolio();
           Portfolios = new ObservableCollection<PortfolioPerformance>(portfolios);

        }

    }
The Load event is triggered but possibly doesn't finish in time to set Portfolios as Portfolios is null when it is triggered.

Dharmendar Dhanasekar [Syncfusion]
Replied On May 9, 2016 09:00 AM

[‎5/‎9/‎2016 6:30 PM] Vimal Prabhu Manohkaran:  
Hi Paul,

Thanks for contacting Syncfusion Support. We are working on your requirement and trying to replicate the reported issue. We will get back to you with the working sample on 11-5-16.

Regards,
Dharmendar
 
  


Ashwini Paranthaman [Syncfusion]
Replied On May 12, 2016 12:05 AM

From: Paul Howells
Sent: Wednesday, May 11, 2016 8:57 PM
To: Syncfusion Support
Subject: RE: Syncfusion support community forum 124002, Binding to an asynchronous REST service, has been updated.
 
 
Hi, 
 
How did you go with this issue? Is there any progress? 
 
Thanks, 
Paul 


Akila Rajaram [Syncfusion]
Replied On May 13, 2016 02:04 AM

Hi Paul, 
 
We are able to reproduce the reported problem while fetching the data asynchronously . We are current checking on this . We have attached the sample we tried for your reference and we will update further details on 13th May 13, 2016.  
 
 
Regards, 
Akila R. 


Akila Rajaram [Syncfusion]
Replied On May 17, 2016 09:32 AM

Hi Paul,  

We are sorry for the delay. 

We were able to load the data from service using ODataClient . Initially, we were able to reproduce the issue which occurred because of slow internet connection. However, when testing our sample with a good internet connection we were able to load the data from the services. We have attached the sample and a video for your reference which you can download from the below link.  


Regards, 
Akila R. 
  


Paul
Replied On May 18, 2016 04:25 AM

Hi,
I have run the sample project using the UWP project and then the Windows Phone as the start up project. Both projects run successfully but the datagrid is not displayed at all.
I tried simplifying the LoadData method to remove the dependency on the OData service but still the datagrid is not displayed:

async void LoadData()
        {
            //gridSource = new ObservableCollection<Order>();
            //var client = new ODataClient("http://services.odata.org/Northwind/Northwind.svc/");
            //var units = await client.FindEntriesAsync("Orders");
            //var itemCollection = units.ToList();

            //var itemCollection1 = new List<IDictionary<string, object>();
            //itemCollection.Add("test", new Order { OrderID = 1, OrderDate = DateTime.Today });

            Device.BeginInvokeOnMainThread(() =>
            {
                //foreach (var item in itemCollection)
                //{
                //    var order = new Order();
                //    foreach (var prop in item)
                //    {
                //        order.GetType().GetRuntimeProperty(prop.Key).SetValue(order, prop.Value);
                //    }
                //    gridSource.Add(order);
                //}
                Order order = new Order();
                order.OrderID = 1;
                order.OrderDate = DateTime.Today;
                gridSource.Add(order);
            });
        }

Your comment "Initially, we were able to reproduce the issue which occurred because of slow internet connection" is also a concern as I would expect the data to still be displayed even if the OData service takes a while.

thanks,
Paul


Akila Rajaram [Syncfusion]
Replied On May 19, 2016 06:59 AM

 
Hi Paul,  
We have created an incident for the reported problem. We will assist you further through the incident under your Direct-Trac account. Our Direct Trac support system can be accessed from the following link:   
Regards,  
Akila R. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;