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

[Solved] childgrid with different columns

1 Answer 131 Views
Grid
This is a migrated thread and some comments may be shown as answers.
regis
Top achievements
Rank 1
regis asked on 02 Jun 2009, 05:17 PM
Hi Everyone,

I am wondering if it's possible to have childgrids at he same level but with different columns kind of:


 ID        |    NAME  
                 
    1          Name1  
 
           -        Column1    | Column2  
                     data           data  
 
    2          Name2  
 
           -        Column3    | Column4  
                      data          data  
 
    3                Name3  
 
           -        Column1    |    Column3    |    Column4  
                      data            data           data 

Column1, Column2, Column3 and Column4 are the same in each childgrid

   In fact each childgrid would be independant from the others in terms number of columns. Some column would show and other wouldn't depending of the data in the database (if N/A the column doen't show for that childgrid)

I am changing the datatable  for each childgrid (because they are different) DetailTableDataBind but the columns generated doesn't maps the datatable.

Right now every childgrid is following the pattern of the first chidlgrid leaving blank field even if the column is not in the datatable.

 ID        |    NAME     
                    
    1          Name1     
    
           -        Column1    | Column2     
                     data           data     
    
    2          Name2     
    
           -        Column1    | Column2    |   Column3    |    Column4     
                                                  data          data     
    
    3                Name3     
    
           -        Column1    | Column2    |   Column3    |    Column4     
                      data                        data           data    
 



I hope i am clear enough

Thank you

Regis

1 Answer, 1 is accepted

Sort by
0
Accepted
Veli
Telerik team
answered on 05 Jun 2009, 09:21 AM
Hi regis,

RadGrid's nested structure is designed to allow for multiple nested tables with a similar structure to desplay a consistent set of detail data. Therefore, by default, RadGrid does not allow changes in the nested table structure after the first nested table has been created. The reason for this is that RadGrid uses one and the same structure for all its nested tables after it has created the first one.

Nevertheless, the functionality you need can be implemented easily with RadGrid's NestedViewTemplate feature. You would need to define a second inner RadGrid in your parent RadGrid's NestedViewTemplate and declaratively set the inner RadGrid's NeedDataSource event handler. Finally, in your event handler, you can get the parent item's key values and use them to extract your own detail data to specify as RadGrid's data source.

In this manner, for each item of your parent RadGrid you could have a child RadGrid independent of the other items, bound to whatever data you have specified for it in its NeedDataSource event.

For better understanding, I have attached a small project demonstrating the above mentioned approach. You can give it a  try and see how it works for you.

All the best,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
regis
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or