Hi,
Is it possible? A grid with dynamic structure of columns on 2nd level of the grid.
Example:
A grid with 2 rows ( RowA, RowB )
When I click on RowA , it opens another row (2nd level ) with columns X,Y,Z
and
When I click on RowB, it opens other structure with columns A,B,C
Thanks,
Thiago Scaranto
Is it possible? A grid with dynamic structure of columns on 2nd level of the grid.
Example:
A grid with 2 rows ( RowA, RowB )
When I click on RowA , it opens another row (2nd level ) with columns X,Y,Z
and
When I click on RowB, it opens other structure with columns A,B,C
Thanks,
Thiago Scaranto
6 Answers, 1 is accepted
0
Hello Thiago,
Indeed such a setup can be created. For that purpose you can enable the auto-generate columns functionality on the second level of the grid and bind the child GridTableView in the DetailTableDataBind event. The columns in that case will create according to the DataTable structure assigned to the DataSource property.
Regards,
Angel Petrov
Telerik
Indeed such a setup can be created. For that purpose you can enable the auto-generate columns functionality on the second level of the grid and bind the child GridTableView in the DetailTableDataBind event. The columns in that case will create according to the DataTable structure assigned to the DataSource property.
Regards,
Angel Petrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Thiago
Top achievements
Rank 1
answered on 09 Aug 2013, 02:34 PM
Hello Angel,
Thanks for answer.
I tried the solution but when I set the DataSource property all others open rows got the structure of columns of the last rule applied.
Thanks for answer.
I tried the solution but when I set the DataSource property all others open rows got the structure of columns of the last rule applied.
0
Hello Thiago,
Apologies for misleading you in my previous post. Actually when the user first expands an item the structure of the detail table is created and cloned for every next one. In order to create a different structure you can use a NestedViewTemplate instead and place a RadGrid inside it. Following this approach I have prepared for you a sample project which demonstrates how this can be implemented.
Regards,
Angel Petrov
Telerik
Apologies for misleading you in my previous post. Actually when the user first expands an item the structure of the detail table is created and cloned for every next one. In order to create a different structure you can use a NestedViewTemplate instead and place a RadGrid inside it. Following this approach I have prepared for you a sample project which demonstrates how this can be implemented.
Regards,
Angel Petrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Thiago
Top achievements
Rank 1
answered on 19 Aug 2013, 02:41 PM
Hello Angel,
Thanks a lot, I did as you show me on difftables project and is working great.
Now, I need another help, I think will be simple.
How can I have a detailtable for RadGridChild ?
<NestedViewTemplate>
as <telerik:RadGrid runat="server" ID="RadGridChild" OnNeedDataSource="RadGridChild_NeedDataSource"></telerik:RadGrid>
</NestedViewTemplate>
Regards,
Thiago Scaranto
Thanks a lot, I did as you show me on difftables project and is working great.
Now, I need another help, I think will be simple.
How can I have a detailtable for RadGridChild ?
<NestedViewTemplate>
as <telerik:RadGrid runat="server" ID="RadGridChild" OnNeedDataSource="RadGridChild_NeedDataSource"></telerik:RadGrid>
</NestedViewTemplate>
Regards,
Thiago Scaranto
0
Princy
Top achievements
Rank 2
answered on 21 Aug 2013, 11:58 AM
Hi Thiago,
Please try the below code snippet to add a detail table.
ASPX:
C#:
Thanks,
Princy
Please try the below code snippet to add a detail table.
ASPX:
<telerik:RadGrid ID="RadGrid1" Width="97%" AllowPaging="True" PageSize="15" runat="server" AllowSorting="true" OnNeedDataSource="RadGrid1_NeedDataSource" OnItemCommand="RadGrid1_ItemCommand" GridLines="None"> <MasterTableView Width="100%" HierarchyLoadMode="ServerOnDemand" DataKeyNames="TestItemString"> <NestedViewTemplate> <telerik:RadGrid runat="server" ID="RadGridChild" OnNeedDataSource="RadGridChild_NeedDataSource" OnDetailTableDataBind="RadGridChild_DetailTableDataBind"> <MasterTableView Width="100%" CommandItemDisplay="Top" AllowMultiColumnSorting="True"> <DetailTables> <telerik:GridTableView CommandItemDisplay="Top" Name="child" Width="100%"> </telerik:GridTableView> </DetailTables> </MasterTableView> </telerik:RadGrid> </NestedViewTemplate> </MasterTableView> </telerik:RadGrid>C#:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) { List<TestItem> item = new List<TestItem>(); item.Add(new TestItem() { TestItemString = "A" }); item.Add(new TestItem() { TestItemString = "B" }); RadGrid1.DataSource = item; } public class TestItem { public string TestItemString { get; set; } } public class TableOneStructure { public string A { get; set; } public string C { get; set; } public string B { get; set; } } public class TableTwoStructure { public string X { get; set; } public string Y { get; set; } public string Z { get; set; } } public class TableTreeStructure { public string P { get; set; } public string Q { get; set; } public string R { get; set; } } protected void RadGridChild_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) { if (!e.IsFromDetailTable) { RadGrid grid = sender as RadGrid; GridDataItem parentItem = (grid.NamingContainer as GridNestedViewItem).ParentItem; if (parentItem.GetDataKeyValue("TestItemString").ToString() == "A") { List<TableOneStructure> dt = new List<TableOneStructure>(); dt.Add(new TableOneStructure() { A = "A string", B = "B string", C = "C string" }); dt.Add(new TableOneStructure() { A = "A string", B = "B string", C = "C string" }); grid.DataSource = dt; } else { List<TableTwoStructure> dt = new List<TableTwoStructure>(); dt.Add(new TableTwoStructure() { X = "x string", Y = "y string", Z = "z string" }); dt.Add(new TableTwoStructure() { X = "x string", Y = "y string", Z = "z string" }); grid.DataSource = dt; } } } protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e) { if (e.CommandName == "ExpandCollapse") { GridDataItem item = e.Item as GridDataItem; RadGrid grid = item.ChildItem.FindControl("RadGridChild") as RadGrid; grid.Rebind(); } } protected void RadGridChild_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e) { GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem; switch (e.DetailTableView.Name) { case "child": { List<TableTreeStructure> dt1 = new List<TableTreeStructure>(); dt1.Add(new TableTreeStructure() { P = "ppp", Q = "qqq", R = "rrr" }); dt1.Add(new TableTreeStructure() { P = "ppp", Q = "qqq", R = "rrr" }); e.DetailTableView.DataSource = dt1; break; } } }Thanks,
Princy
0
Thiago
Top achievements
Rank 1
answered on 26 Aug 2013, 01:37 PM
Princy,
Thanks a lot, It worked perfectly.
Regards,
Thiago Scaranto
Thanks a lot, It worked perfectly.
Regards,
Thiago Scaranto