This is a migrated thread and some comments may be shown as answers.

Lazy Loading Details...

3 Answers 112 Views
GridView
This is a migrated thread and some comments may be shown as answers.
mark baer
Top achievements
Rank 1
mark baer asked on 10 May 2010, 07:13 PM
I am fairly familiar with the Gridview Control, but I haven't done any Master/Details with expandable rows...The "Detail" rows will be too many to bring back in the initial load so I need to fetch them via a service when the user clicks teh "Expand" plus sign...Can anybody point me in the right direction on how to accomplish this.  I've reviewed the master/Detail row examples here, but I haven't seen lazy loading yet or how to call the service when the row is selected/expanded.

Thank you very much.

mark

3 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 11 May 2010, 10:33 AM
Hi mark baer,

I believe that my blog post is exactly what you are looking for. Please, take a look at it.

Another way to achieve something similar would be to attach to the RowDetailsVisibilityChanged event of the grid. Something like this:

private void RadGridView_RowDetailsVisibilityChanged(object sender, Telerik.Windows.Controls.GridView.GridViewRowDetailsEventArgs e)
        {
            if (e.Visibility == Visibility.Visible)
            {
                // This means that row detail are being shown.
                var masterEntity = e.Row.DataItem;

                // Kick of a service here that will retrieve details based on the master entity.
                // The service can feed another RadGridView inside the row details. Or anything
                // else, as a matter of fact.
            }
        }

In case you want to pull details data each time when row details are shown then RowDetailsVisibilityChanged is your event. You might want to do this if data on your server is constantly changing and it can be different between two consecutive showings of the row details of a row.

In case data on your server is fairly static and you want to pull details data only once, i.e. the very first time row details are loaded, then LoadingRowDetails is your event. It will fire once and only once the very first time row details are being shown. It is the "lazy" event you are looking for. It will not be fired until someone shows the details for the very first time.

More info on row details you can find in our online documentation.

For many other examples of using row details, you can check out my series of blog posts. You might find interesting implementations there which will give you an idea of how things work.

Let me know if you have any questions, troubles or difficulties. I would be glad to help.

Sincerely yours,
Ross
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
mark baer
Top achievements
Rank 1
answered on 12 May 2010, 12:13 AM
Thanks for responding...I reviewed your posts/blogs and I think I am close.  I created my Details in a User Control and I'm using the RowDetailsVisibilityChanged to call a WCF service to get the details for that Row...In my Details Control, I have a Tab Control with 2 Grids...The data I get back will either be "Approved" or "Not Approved" so I will use LINQ to query that data out of the service result set into two smaller collections which will be bound to the grids...But since the service gets called asynchronously, I'm not sure how to get the data to the 2 Grids in the Details User Control.  I played with just using a DataTemplate in the same xaml page instead of a user control, but I'm not sure how to get that data to the grids after it returns from the service...

Thanks

Mark

My code:

private

 

void radgridElements_RowDetailsVisibilityChanged(object sender, Telerik.Windows.Controls.GridView.GridViewRowDetailsEventArgs e)

 

{

 

 

//-----------------------------------------------

 

 

    if (e.Visibility == Visibility.Visible)

 

    {

 

        ElementDefinition elementDefinition = radgridTemplateElements.SelectedItem as ElementDefinition;

 

 

         

 

 

        InquiryServiceProxy.
InquiryClient serviceProxy = new MyApp.InquiryServiceProxy.InquiryClient();

 

        serviceProxy.FetchCompleted +=

new EventHandler<MyApp.InquiryServiceProxy.FetchCompletedEventArgs>(serviceProxy_FetchTemplateElementsCompleted);

 

    // Now call the service    
    serviceProxy.FetchAsync(params);

    }

 

}

0
Rossen Hristov
Telerik team
answered on 12 May 2010, 08:32 AM
Hello mark baer,

Since you have encapsulated your two grids in your own user control you can either expose them for the outside world as public properties or create a public method of your user control, which you will call once the service is done. You can pass in the data through this public method and bind the grids that are inside the user control. There are many ways you can take the data and pass it to the grids. It is up to you to decide how to do this.

Finally, in the event handler, e.DetailsElement will be the instance of your user control. You can cast it to your type and do the necessary things on it.

I hope this helps.

Sincerely yours,
Ross
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
mark baer
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
mark baer
Top achievements
Rank 1
Share this question
or