RadGridView hierarchy async lazy load

1 Answer 127 Views
GridView
Tibor
Top achievements
Rank 1
Iron
Iron
Tibor asked on 19 Oct 2023, 01:49 PM

What I'm trying to achieve is a RadGridView with expanding/collapsing hierarchy rows that uses load on demand data that I get from my server using a REST API call. A separate REST call is started every time a RowSourceNeeded event is fired for a row. The problem is that the GUI thread does not seem to wait for my call and the row tries to expand then immediately collapses again (so basically the whole expand operation does not wait until my data is loaded) after which the grid starts behaving erroneously, which includes;

    - the application hangs for a few seconds when I click an expanded hierarchy row

   - clicking a hierarchy row makes the whole grid scroll down a bit

 

Leaving the async API call out for testing purposes and filling the row below with dummy data immediately solves all these problems, so I'm certain it is the cause of these problems.

private async void radGridView1_RowSourceNeededAsync(object sender, GridViewRowSourceNeededEventArgs e)
        {
            MainJobObject mainJobObject = e.ParentRow.DataBoundItem as MainJobObject;

            //make the RESTAPI call here to retrieve the attachments of this job
            List<IJobDocument> mainJobObjectAttachments = await FillMainJobObjectWithAttachmentsFromBackend(mainJobObject.JobId);

            foreach (IJobDocument attachment in mainJobObjectAttachments)
            {
                GridViewRowInfo row = e.Template.Rows.NewRow();
                row.Cells["MainJobID"].Value = mainJobObject.JobId;
                row.Cells["Status"].Value = attachment.StatusObject.Status;
                row.Cells["UploadDate"].Value = attachment.StatusObject.UploadDate;
                row.Cells["AttachmentID"].Value = attachment.IJobDocumentId;
                row.Cells["AttachmentType"].Value = attachment.AttachmentType;
                row.Cells["ServisnyTechnik"].Value = attachment.ServisnyTechnik;
                row.ErrorText = attachment.Error;

                e.SourceCollection.Add(row);
            }
        }

1 Answer, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 23 Oct 2023, 08:18 AM

Hello Tibor,

Thank you for the provided code snippet.

I will start with the RowSourceNeeded event's purpose is to provide the child data for an expanded parent row. Since the await operator allows the UI thread to continue execution it continues and the view is expanded, however, the rows are added after that, which is why you probably will need to re-expand the row to see the child rows. Also, I think this is the reason why the control is acting erroneously.

RadGridView cannot support this scenario due to the event-driven behavior of the Load on-demand mode. A possible solution here is to pre-load the data when the grid starts and cache it. This way you will be able to synchronously load the data when a row is expanded. 

Another possible solution is to refresh the control in the RowSourceNeeded event as demonstrated in this forum thread. I am not sure if this approach will work in your case as I am not aware of how much time it requires for the Rest API to return the new rows. However, you can test it. Also, I need to point out that this approach could hit the performance as it will refresh the whole grid if there are a lot of rows. I would suggest testing it in all scenarios to ensure it will work in your application.

I hope you will find my reply helpful.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
GridView
Asked by
Tibor
Top achievements
Rank 1
Iron
Iron
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or