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.

Async On Demand Loading

Thread ID:

Created:

Updated:

Platform:

Replies:

129665 Mar 27,2017 11:01 AM Mar 30,2017 03:07 PM WPF 1
loading
Tags: SfTreeGrid
Frido Dombek
Asked On March 27, 2017 11:01 AM

Hi,I have to load data asynchronously from the web and want to display it in a SfTreeGrid using 'On Demand Loading'. 
However I couldn't figure out a way to populate the tree on demand when I'm calling and awaiting async functions to load the data.

As an example, if modify your OnDemandLoading Example and add a await Task.Delay(1) call to the code, it won't populate the tree with tree nodes anymore.


/// <summary>
/// Gets the reportees.
/// </summary>
/// <param name="bossID">The boss ID.</param>
/// <returns></returns>
public async Task<IEnumerable<EmployeeInfo>> GetReportees(int bossID)
{
 
    List<EmployeeInfo> list = new List<EmployeeInfo>();
    int loc = FindID(bossID);
    if (loc > -1)
    {
        await Task.Delay(1);
        while (loc < this.EmployeeDetails.Count && this.EmployeeDetails[loc].ReportsTo == bossID)
            list.Add(this.EmployeeDetails[loc++]);
    }
    return list;
}


I then await this function in:
async void AssociatedObject_RequestTreeItems(object sender, TreeGridRequestTreeItemsEventArgs args)

How can I populate the SfTreeGrid on demand with data that is loaded asynchronously?

Regards and Thanks,
Frido

Muthukumar Kalyanasundaram [Syncfusion]
Replied On March 30, 2017 03:07 PM

Hi Frido, 

Thank you for contacting Syncfusion support. 

We have checked your query. We are able to reproduce the reported query in our end. You can overcome this problem by handling the AutoResetEvent. For your reference, we have attached the code snippet and sample in the below location, 

Code Snippet: 
 
System.Threading.AutoResetEvent autoreset = new System.Threading.AutoResetEvent(false); 
 
async void AssociatedObject_RequestTreeItems(object sender, TreeGridRequestTreeItemsEventArgs args) 
{ 
    if (args.ParentItem == null) 
    { 
        //get the root list - get all employees who have no boss  
        args.ChildItems = viewModel.EmployeeDetails.Where(x => x.ReportsTo == -1); //get all employees whose boss's id is -1 (no boss) 
    } 
    else //if ParentItem not null, then set args.ChildList to the child items for the given ParentItem. 
    {   //get the children of the parent object 
        EmployeeInfo emp = args.ParentItem as EmployeeInfo; 
        if (emp != null) 
        { 
            Task t = Task.Run(() => 
            { 
                GetChildItem(args); 
            }); 
            autoreset.WaitOne(); 
        } 
    } 
} 
 
private async void GetChildItem(TreeGridRequestTreeItemsEventArgs args) 
{ 
    EmployeeInfo emp = args.ParentItem as EmployeeInfo; 
    args.ChildItems = await viewModel.GetReportees(emp.ID); 
    autoreset.Set(); 
} 



Please let us know if you have any query. 

Regards, 
Muthukumar K 


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.

;