Modified Data not bounded to SfDataGrid

Hi ,
I have an async task that would load the Grid data property in the viewmodel constructor. This async task is needed to load the data from the webservice call. Once the data got bounded back to the property bounded to the SfDataGrid , the Grid doesn't get refreshed.
Below is the code that i have
public ViewModel()
{
SetRowstoGenerate(50);
}
public async void SetRowstoGenerate(int count)
{
order = new OrderInfoRepository();
ordersInfo = await order.GetOrderDetails(count);
}
if i remove async/await from above, and bind static data instead of the web service data , the Grid loads just fine.
Could you let me know how i can make this work with async/await keywords.

8 Replies

SS Sivaraman Sivagurunathan Syncfusion Team January 14, 2018 05:43 PM UTC

Hi Joseph, 
 
Thanks for using Syncfusion Support. 
 
We have checked your query. you can load the data for the SfDataGrid using async await Keyword. we have prepared sample for your reference you can download the same from the below link. The below code illustrate how to use async await keyword in SetRowstoGenerate. 
 
 
public ViewModel() 
{ 
    SetRowstoGenerate(50); 
} 
 
public async void SetRowstoGenerate(int count) 
{ 
    order = new OrderInfoRepository(); 
    ordersInfo = order.GetOrderDetails(count); 
    await Task.Delay(new TimeSpan(0, 0, 5)); 
} 
 
 
Please let us know, if you need any further assistance. 
 
Regards, 
Sivaraman  



JM Joseph Michael January 17, 2018 10:59 AM UTC

Hi,

if i swap the lines in the below order the data doesn't bind. How do we deal with this scenario?

await Task.Delay(new TimeSpan(0, 0, 5));
ordersInfo = order.GetOrderDetails(count);




SS Sivaraman Sivagurunathan Syncfusion Team January 19, 2018 05:35 PM UTC

Hi Joseph, 
 
Sorry for the delay. 
 
We have checked your query. you can work with this scenario too for that we need to implement the INotifyPropertyChanged interface properly. We have prepared the sample for your reference you can download the same from the below link. 
 
 
Regards, 
Sivaraman  



SS Sivaraman Sivagurunathan Syncfusion Team January 19, 2018 05:35 PM UTC

Hi Joseph, 
 
Sorry for the delay. 
 
We have checked your query. you can work with this scenario too for that we need to implement the INotifyPropertyChanged interface properly. We have prepared the sample for your reference you can download the same from the below link. 
 
 
Regards, 
Sivaraman  



JM Joseph Michael January 23, 2018 11:09 AM UTC

Hi sivaraman

the source code linked with the last post is not working. It crashes while running. Getting an unhandled exception when i ran it.




SS Sivaraman Sivagurunathan Syncfusion Team January 24, 2018 09:49 AM UTC

Hi Joseph,    
    
Sorry for the inconvenience caused.    
    
We have checked the reported “unhandled ArgumentOutOfRangeException” issue from our side. This is a known issue from our side and we have fixed it from our side. The fix will be included in our 2018 Vol 1 main release which is scheduled to rolled out by the mid of February, 2017.     
    
Regards,    
Sivaraman      



JM Joseph Michael January 24, 2018 12:55 PM UTC

Hi sivaraman,

i understand that this issue will be fixed in upcoming release. But my question is, if you could provide me a sample of data getting rebounded to SfDataGrid with an await operation in the code? 

await Task.Delay(new TimeSpan(0, 0, 5));
ordersInfo = order.GetOrderDetails(count);
 
Or could you please provide me a sample code, where the data to SfDataGrid can be bounded on a button click .

This is how my constructor looks like. 



My GetOrderDetails method looks like below



i have put a comment where the problem is when binding data to SfDataGrid. But when i bind a label with orderDetails data. the label gets updated.

The App after binding looks like this without await call in GetOrderDetails Method



When i keep the await the app screen looks like this







SS Sivaraman Sivagurunathan Syncfusion Team January 25, 2018 06:10 PM UTC

Hi Joseph,  
 
We have prepared the sample based on Async await operation and attached for your reference you can download the same from the below link. 
And we have provide the custom assemblies for the “unhandled exception” issue. In the below thread you can download the custom assemblies in the below link. 
 
 
 
The below code illustrate how to use Async await. 
 
 
<syncfusion:SfDataGrid x:Name="dataGrid" 
                        ColumnSizer="Star" 
                        ItemsSource = "{Binding OrdersInfo}" 
                        AutoGenerateColumns="True"/> 
 
public async Task<ObservableCollection<OrderInfo>> GetOrderDetails(int count) 
{ 
    SetShipCity(); 
    this.OrderedDates = GetDateBetween(2000, 2014, count); 
    ObservableCollection<OrderInfo> orderDetails = new ObservableCollection<OrderInfo>(); 
    await Task.Delay(10); 
    for (int i = 10001; i <= count + 10000; i++) 
    { 
        var shipcountry = ShipCountry[random.Next(5)]; 
        var shipcitycoll = ShipCity[shipcountry]; 
 
        var ord = new OrderInfo() 
        { 
            OrderID = i, 
            CustomerID = CustomerID[random.Next(15)], 
            EmployeeID = random.Next(1700, 1720), 
            FirstName = FirstNames[random.Next(15)], 
            LastName = LastNames[random.Next(15)], 
            Gender = Genders[random.Next(5)], 
            ShipCountry = ShipCountry[random.Next(5)], 
            ShippingDate = this.OrderedDates[i - 10001], 
            Freight = (Math.Round(random.Next(1000) + random.NextDouble(), 2)), 
            IsClosed = ((i % 2 == 0) ? true : false).ToString(), 
            ShipCity = shipcitycoll[random.Next(shipcitycoll.Length - 1)], 
            ButtonVisibility = false, 
    }; 
        orderDetails.Add(ord); 
    } 
    return orderDetails; 
} 
 
public async void SetRowstoGenerate(int count) 
{ 
    // await Task.Delay(new TimeSpan(0, 0, 5)); 
    order = new OrderInfoRepository(); 
    OrdersInfo =await order.GetOrderDetails(count); 
} 
 
Replace the custom assemblies in the below mentioned location.            
  
{Syncfusion Installed location}\Essential Studio\15.4.0. 20 \Xamarin\lib\pcl\Syncfusion.SfDataGrid.XForms.dll     
{Syncfusion Installed location}\Essential Studio\15.4.0. 20 \Xamarin\lib\android\Syncfusion.SfDataGrid.XForms.dll    
{Syncfusion Installed location}\Essential Studio\15.4.0. 20 \Xamarin\lib\android\Syncfusion.SfDataGrid.XForms.Android.dll    
{Syncfusion Installed location}\Essential Studio\15.4.0. 20 \Xamarin\lib\ios-unified\Syncfusion.SfDataGrid.XForms.dll   
{Syncfusion Installed location}\Essential Studio\15.4.0. 20 \Xamarin\lib\ios-unified\Syncfusion.SfDataGrid.XForms.iOS.dll     
{Syncfusion Installed location}\Essential Studio\15.4.0. 20 \Xamarin\lib\uwp\Syncfusion.SfDataGrid.XForms.dll   
{Syncfusion Installed location}\Essential Studio\15.4.0. 20 \Xamarin\lib\uwp\Syncfusion.SfDataGrid.XForms.UWP.dll 

Disclaimer: Please note that we have created this assembly for the version 15.4.0. 20.
 
  
Regards,  
Sivaraman   
 


Loader.
Up arrow icon