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

export to excel multi layer grid

9 Answers 47 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lina
Top achievements
Rank 1
Lina asked on 25 Aug 2013, 07:18 PM
I have multi layer grid with 4 levels using NestedViewTemplate.
when i export to excel, only 2 levels are exported. how can i export all 4 levels?
the grid datasources is updated in code behind, on OnNeedDataSource  event
the strcuture is:
<telerik:RadGrid
    <ExportSettings ExportOnlyData="true" IgnorePaging="true" OpenInNewWindow="true">
       <Excel Format="Html"></Excel>
   </ExportSettings>
   <MasterTableView...
      <CommandItemSettings ShowExportToExcelButton="true"></CommandItemSettings>
      <NestedViewTemplate>
         <telerik:RadGrid
            <MasterTableView
               <NestedViewTemplate>
                  <telerik:RadGrid
                     <MasterTableView
                       <NestedViewTemplate>
                         <telerik:RadGrid
                            <MasterTableView

9 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 28 Aug 2013, 01:19 PM
Hello Lina,

I guess you do not expand all items on each level. In order to do so you have to loop through all items and manually set their Expanded property to true. Another approach is to enable HierarchyDefaultExpanded of all tables. 

Regards,
Kostadin
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
Lina
Top achievements
Rank 1
answered on 28 Aug 2013, 01:37 PM
thanks Kostadim.
how do i do it? on which event and how to do it nested in the 4 levels?
0
Kostadin
Telerik team
answered on 02 Sep 2013, 08:35 AM
Hello Lina,

I prepared a small sample and attached it to this forum post. If you are having only RadGrids in the NestedViewTemplate I would recommend you instead using a NestedViewTemplate to use HierarchyGrid. Check out the following live example.

Regards,
Kostadin
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
Lina
Top achievements
Rank 1
answered on 02 Sep 2013, 10:57 AM
thanks Kostadin, the grid is exported in all levels :-)

1) one minor issue:
some of the the columns contain formatting
  DataFormatString="{0:c}"
  DataFormatString="{0:P}"
in the exported excel, there is no formatting in first level (RadGrid1) - no $ and no %

2) when i tried to use HierarchyGrid (DetailTables) as you suggested, one of the problem i had was binding the data source in the code behind inside DetailTableDataBind event

how to declare the grid correctly, so the GetDataKeyValue in the nested grid will work correctly (in the method Grid1_DetailTableDataBind)?
each level in the grid need additional key to the level before


<telerik:RadGrid id="Grid1"   OnNeedDataSource="Grid1_NeedDataSource" runat="server" OnDetailTableDataBind="Grid1_DetailTableDataBind">
                <MasterTableView>
                     <DetailTables>
                        <telerik:GridTableView DataKeyNames="key1,key2" Name="Grid2" runat="server" Height="100%">
                            <DetailTables>
                                <telerik:GridTableView DataKeyNames="key1,key2,key3" Name="Grid3" runat="server" Height="100%">
                                    <DetailTables>
                                        <telerik:GridTableView DataKeyNames="key1,key2,key3,key4" Name="Grid4">
                                        
    protected void Grid1_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
    {
        GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
        switch (e.DetailTableView.Name)
        {
            case "Grid2":
                {
                    string key1 = parentItem.GetDataKeyValue("key1").ToString();
                    // perform sql to get data
                    e.DetailTableView.DataSource = ....
                    break;
                }

            case "Grid3":
                {
                    string key1 = parentItem.GetDataKeyValue("key1").ToString();
                    string key2 = parentItem.GetDataKeyValue("key2").ToString();
                    // perform sql to get data
                    e.DetailTableView.DataSource = ....
                    break;
                }
            case "Grid4":
                {
                    string key1 = parentItem.GetDataKeyValue("key1").ToString();
                    string key2 = parentItem.GetDataKeyValue("key2").ToString();
                    string key3 = parentItem.GetDataKeyValue("key3").ToString();
                    // perform sql to get data
                    e.DetailTableView.DataSource = ....
                    break;
                }

        }
    }                       
 
0
Kostadin
Telerik team
answered on 05 Sep 2013, 10:28 AM
Hello Lina,

You could use a mso-number-format  and set a format of each cell in your grid. I would suggest you to review the following help article which elaborates more on this matter. As to your second question you must set the DataKeyNames property of every parent table view in the hierarchy to specify the fields in the table's data source that are used for linking to child tables. The DataKeyNames property must list the exact names of these fields as they appear in the parent table's data source. I am not sure what exactly is not working in your case. Could you please provide more details about the issue you are facing?
 
Regards,
Kostadin
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
Lina
Top achievements
Rank 1
answered on 12 Sep 2013, 05:24 PM
when i use mso-number-format with Currency format and the value is zero, instead of zero, there is $-
e.Cell.Style["mso-number-format"] = @"Currency";
0
Kostadin
Telerik team
answered on 17 Sep 2013, 10:23 AM
Hello Lina,

You could use the following approach to display a currency into the grid.
e.Cell.Style["mso-number-format"] = @"$0.00";


Regards,
Kostadin
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
Lina
Top achievements
Rank 1
answered on 17 Sep 2013, 10:26 AM
this approach assume $ as currency. how can i do it with general currency?
0
Accepted
Kostadin
Telerik team
answered on 20 Sep 2013, 11:17 AM
Hi Lina,

In this case you have to use the previous approach "@"Currency";". When a cell contains a 0 you could leave it unformatted and this way the number will be displayed but without the currency symbol.

Regards,
Kostadin
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.
Tags
Grid
Asked by
Lina
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Lina
Top achievements
Rank 1
Share this question
or