2013Q1 RadGridView Export question

4 posts, 0 answers
  1. Ricky
    Ricky avatar
    9 posts
    Member since:
    May 2013

    Posted 17 May 2013 Link to this post

    Hi there,

    my problem is I have a grid view, and I have tons of login in xaml which perform the grouping and aggregate function, some of the group header/footer may have a DataTemplate to host the data. When I export the grid using the native Export function, I have the following issue:

    1. I lost the Group Header, the column I am used to group is not shown in UI and I disallow use to change the grouping
    2. I lost the ColumnGroups
    3. Some of the cell is incorrect datatype (e.g. number and was interpreted as date in Excel)
    4. All the template data cannot be displayed, and what's generated is the datatype instead of the string value on the grid (same as copy from the grid directly using Ctrl-C)

    Any help will be appreciated!

    Here are some examples of the xaml:

    1. Grid Definition
    <telerik:RadGridView Name="GridViewMyGrid"                                          
         ItemsSource="{Binding MyCollection}" 
         AutoGenerateColumns="False" 
         IsReadOnly="True"
         CanUserFreezeColumns="False"
         GroupRenderMode="Flat"
         ShowColumnFooters="True"
         ShowGroupFooters="True"
         AutoExpandGroups="True"
         IsFilteringAllowed="False"
         ShowGroupPanel="False" 
         FrozenColumnCount="2" 
         SelectionMode="Extended" 
         >

    2. Column Group
    <telerik:RadGridView.ColumnGroups>
        <telerik:GridViewColumnGroup  Name="Group1ColumnGroup" 
                                Header="Group1">
            <telerik:GridViewColumnGroup.HeaderTemplate>
                <DataTemplate>
                    <TextBlock Text="Group1" 
                            TextAlignment="Center" 
                            FontWeight="Bold"></TextBlock>
                </DataTemplate>
            </telerik:GridViewColumnGroup.HeaderTemplate>
        </telerik:GridViewColumnGroup>


    3. Column (I have tons of column and just show two here, the 1st is used for grouping)
    <telerik:RadGridView.Columns>                            
        <telerik:GridViewDataColumn DataMemberBinding="{Binding GroupName}" ShowColumnWhenGrouped="False" />
        <telerik:GridViewDataColumn Header="Item1"
                                    DataMemberBinding="{Binding Item1}">                            
            <telerik:GridViewDataColumn.AggregateFunctions>
                <telerik:FirstFunction/>
            </telerik:GridViewDataColumn.AggregateFunctions>
            <telerik:GridViewDataColumn.GroupFooterTemplate>
                <DataTemplate>
                    <TextBlock FontWeight="Bold">
                        <Run Text="Subtotal "/>
                        <Run Text="{Binding Value.GroupName}"/>
                    </TextBlock>                                        
                </DataTemplate>
            </telerik:GridViewDataColumn.GroupFooterTemplate>
            <telerik:GridViewColumn.Footer>
                <TextBlock FontWeight="Bold">
                    <Run Text="Asset Total"/>
                </TextBlock>
            </telerik:GridViewColumn.Footer>
        </telerik:GridViewDataColumn>


    And here is the method in the code behind to export:

     

    private void ButtonExportStrats_OnClick(object sender, RoutedEventArgs e)
    {
        var grid = GridViewMyGrid;            
        var dialog = new SaveFileDialog();
        dialog.DefaultExt = "*.xlsx";
        dialog.Filter = "Excel Workbook (*.xlsx)|*.xlsx";
        if (dialog.ShowDialog() == true)
        {
            Workbook book = null;
            using (var stream = new MemoryStream())
            {
                grid.Export(stream, new GridViewExportOptions()
                {
                    Format = ExportFormat.Csv,
                    ShowColumnFooters = grid.ShowColumnFooters,
                    ShowColumnHeaders = grid.ShowColumnHeaders,
                    ShowGroupFooters = grid.ShowGroupFooters
                });
                stream.Position = 0;
                book = new CsvFormatProvider().Import(stream);
                if (book != null)
                {
                    var provider = new XlsxFormatProvider();
                    using (var output = dialog.OpenFile())
                    {
                        provider.Export(book, output);
                    }
                }
            }
        }
    }
  2. Yoan
    Admin
    Yoan avatar
    1180 posts

    Posted 20 May 2013 Link to this post

    Hi Ricky,

    You could check this online demo for an example on how you could export the GridView as it is displayed.

    All the best,
    Yoan
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. Ricky
    Ricky avatar
    9 posts
    Member since:
    May 2013

    Posted 20 May 2013 Link to this post

    my code was from that example, and I don't see the result is same as the grid, the export code is simply this in the example:

    var exportOptions = new GridViewExportOptions();
    exportOptions.Format = format;
    exportOptions.ShowColumnFooters = true;
    exportOptions.ShowColumnHeaders = true;
    exportOptions.ShowGroupFooters = true;
    grid.Export(stream, exportOptions);

    which is the same as what I have.
  4. Yoan
    Admin
    Yoan avatar
    1180 posts

    Posted 23 May 2013 Link to this post

    Hi Ricky,

    Could you try isolating the problems in a sample project and send it to us? We will debug it on our side and will assist you further. You can check this blog post for a reference, which shows you how to isolate a problem in a sample project.

    Thank you in advance.

    Regards,
    Yoan
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top