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

Hierarchy grid exporting issues

11 Answers 176 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Martin Roussel
Top achievements
Rank 1
Martin Roussel asked on 29 Oct 2012, 05:30 PM
Hi,

Im using Q2 2012 and having two exporting issues with my ajaxified hierarchical RadGrids:

1-Exporting to Word exports Master and Details tables (all grid rows) whatever if rows are collapsed or expanded. Weird thing, exporting to Excel and PDF are not doing this (they export only Master and expended Details rows, as wanted).

2-Particular rows in my Details table contain a RadTooltip (RadTooltipManager) when mouse hovering on row text. Its working fine but once I trigger a tooltip to appear, the exporting (for Excel, PDF) only export the Master table, ignoring the expending/collapsing. The Word exporting still exports everything (issue #1).

After some research, Ive noted that using <MasterTableView HierarchyLoadMode="ServerBind"...> seems to solve the two issues mentioned but im using "Client" for a reason (especially, row collapsing/expanding on Master row click (rows that contains child only)).

Here is the code:

Markup:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" ClientEvents-OnRequestStart="mngRequestStarted" >
                    <AjaxSettings>
                         
                         <telerik:AjaxSetting AjaxControlID="RadGrid3">
                            <UpdatedControls>
                                <telerik:AjaxUpdatedControl ControlID="RadGrid3" LoadingPanelID="RadAjaxLoadingPanel1" />
                            </UpdatedControls>
                        </telerik:AjaxSetting>
                       
                      </AjaxSettings>
                    </telerik:RadAjaxManager>
                    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="WebBlue" />
 
                   <telerik:RadToolTipManager runat="server" AnimationDuration="300" ShowDelay="600" HideDelay="1" ID="RadToolTipManager1" Width="480px" Height="227px"
                   RelativeTo="Element" Animation="Slide" Position="MiddleRight" OnAjaxUpdate="RadToolTipManager_OnAjaxUpdate" Skin="WebBlue">
                   </telerik:RadToolTipManager>
 
<telerik:RadGrid ID="RadGrid3" runat="server" PageSize="20" AllowPaging="false" Width="100%"
                                AllowSorting="True" AllowFilteringByColumn="false" AllowMultiRowSelection="false"
                                ShowGroupPanel="false" GridLines="None" ShowFooter="false" ShowHeader="true" GroupingEnabled="false"
                                Skin="WebBlue" EnableHeaderContextAggregatesMenu="false" EnableHeaderContextMenu ="false"
                                AutoGenerateColumns="false" EnableViewState="True"
                                OnItemCommand="RadGrid3_OnItemCommand" OnDetailTableDataBind="RadGrid3_DetailTableDataBind" OnNeedDataSource="RadGrid3_NeedDataSource"
                                OnItemDataBound="RadGrid3_OnItemDataBound" OnGroupsChanging="RadGrid3_OnGroupsChanging" OnColumnsReorder="RadGrid3_OnColumnsReorder">
                             
                                <MasterTableView HierarchyLoadMode="Client" Name="Master"
                                 CommandItemDisplay="Top" CommandItemSettings-ShowAddNewRecordButton="false"
                                 CommandItemSettings-ShowExportToExcelButton="true" CommandItemSettings-ShowExportToWordButton="true"
                                 CommandItemSettings-ShowExportToPdfButton="true" CommandItemSettings-ShowExportToCsvButton="true" AllowMultiColumnSorting="true"
                                 Caption="">
                                  
 
                                     <Columns>
                                            <telerik:GridTemplateColumn HeaderText="Col1" UniqueName="str1Value" HeaderStyle-Width="50%" Resizable="true" Reorderable="true" SortExpression="str1Value">
                                                <ItemTemplate>
                                                  <%# Eval("str1Value")%>
                                                </ItemTemplate>
                                            </telerik:GridTemplateColumn>
 
                                            <telerik:GridTemplateColumn HeaderText="Col2" UniqueName="str2Value" HeaderStyle-Width="50%" Resizable="true" Reorderable="true" SortExpression="str2Value">
                                                <ItemTemplate>
                                                  <%# Eval("str2Value")%>
                                                </ItemTemplate>
                                            </telerik:GridTemplateColumn>
                                        
                                      </Columns
 
                                            <DetailTables>
                                                <telerik:GridTableView ShowHeader="false" Name="Detail">
                                                    <Columns>
                                                        <telerik:GridTemplateColumn HeaderText="" UniqueName="strField" HeaderStyle-Width="25%" ItemStyle-CssClass="GridFieldColumn" Resizable="true" Reorderable="true">
                                                            <ItemTemplate>
                                                              <%# Eval("strField")%>
                                                            </ItemTemplate>
                                                        </telerik:GridTemplateColumn>
                                                        <telerik:GridTemplateColumn HeaderText="" UniqueName="strValue" HeaderStyle-Width="75%" Resizable="true" Reorderable="true">
                                                            <ItemTemplate>
                                                              <%# Eval("strValue")%>
                                                              <asp:HyperLink ID="hl" Target="_blank" runat="server" Text='<%# Eval("strLinkResource")%>' NavigateUrl='<%# Eval("strLinkValue")%>'></asp:HyperLink>
                                                            </ItemTemplate>
                                                        </telerik:GridTemplateColumn>
                                                    </Columns>  
                                                </telerik:GridTableView>
                                            </DetailTables>
 
                                </MasterTableView>
 
                                <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
 
                                        <ClientSettings EnablePostBackOnRowClick="False" AllowRowsDragDrop="false" AllowDragToGroup="false" AllowColumnsReorder="false" ReorderColumnsOnClient="false" ColumnsReorderMethod="Reorder">
                                            <Resizing AllowRowResize="False" EnableRealTimeResize="True" ResizeGridOnColumnResize="false" AllowColumnResize="true" AllowResizeToFit="true"/>
                                            <Animation AllowColumnReorderAnimation="false" AllowColumnRevertAnimation="true" />
                                            <Selecting AllowRowSelect="true"  />
                                            <ClientEvents OnRowClick="OnRowClick"></ClientEvents>
                                        </ClientSettings>
 
                                        <SortingSettings SortedBackColor="Azure" EnableSkinSortStyles="false" />
 
                               <GroupingSettings ShowUnGroupButton="true" />
 
                            </telerik:RadGrid>

Javascript:
function mngRequestStarted(ajaxManager, eventArgs) {
 
    if (eventArgs.get_eventTarget().indexOf("ExportToExcelButton") != -1)  {
        eventArgs.set_enableAjax(false);
    }
 
    if (eventArgs.get_eventTarget().indexOf("ExportToWordButton") != -1) {
        eventArgs.set_enableAjax(false);
    }
 
    if (eventArgs.get_eventTarget().indexOf("ExportToPdfButton") != -1) {
        eventArgs.set_enableAjax(false);
    }
 
    if (eventArgs.get_eventTarget().indexOf("ExportToCsvButton") != -1) {
        eventArgs.set_enableAjax(false);
    }
}
 
function OnRowClick(sender, args) {
 
 
    var tableView = args.get_tableView();
 
    if (tableView.get_name() == "Master") {
 
        //getting child row count...this doesnt work when HierarchyLoadMode != "Client"
        var detailTable = args.get_gridDataItem().get_nestedViews()[0];
 
        if (detailTable.get_dataItems().length > 0) {
         
            tableView.clearSelectedItems();
            args.get_item().set_expanded(!args.get_item().get_expanded());
             
        }
    }
 
 
}


Code-Behind:
protected void RadGrid3_OnItemCommand(object o, Telerik.Web.UI.GridCommandEventArgs e)
{
    if (e.CommandName == "RebindGrid")
    {
        RebindGrid(ref RadGrid3, true);
    }
    else
    {
        if (e.CommandName == "ExpandOrCollapse")
        {
            GridDataItem dataItem = RadGrid3.MasterTableView.Items[int.Parse(e.CommandArgument.ToString())] as GridDataItem;
            dataItem.Expanded = !dataItem.Expanded;
            return;
        }
 
          RebindGrid(ref RadGrid3, true);
    }
}
 
protected void RadGrid3_OnColumnsReorder(object o, Telerik.Web.UI.GridColumnsReorderEventArgs e)
{
      RebindGrid(ref RadGrid3, true);
}
 
protected void RadGrid3_OnGroupsChanging(object o, Telerik.Web.UI.GridGroupsChangingEventArgs e)
{
      RebindGrid(ref RadGrid3, true);
}
 
protected void RadGrid3_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
 
 
            BLL b = new BLL();
            RadGrid3.DataSource = b.GetData();
         
 
        if (RadGrid3.DataSource == null)
        {
            RadGrid3.DataSource = new string[] { };
        }
     
 
}
 
protected void RadGrid3_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
{
    if (e.DetailTableView.ParentItem.DataItem != null)
    {
        e.DetailTableView.DataSource = ((ParentDTO)e.DetailTableView.ParentItem.DataItem).colDetails;
    }
}
 
 
protected void RadGrid3_OnItemDataBound(object sender, GridItemEventArgs e)
{
 
    if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "Detail")
    {
        Control HyperLink = e.Item.FindControl("hl");
 
      
        if (((DetailsDTO)e.Item.DataItem).strLinkValue != "" && ((DetailsDTO)e.Item.DataItem).blnIsImage)
        {
            this.RadToolTipManager1.TargetControls.Add(HyperLink.ClientID, ((DetailsDTO)e.Item.DataItem).strLinkValue, true);
        }
 
    }
 
}

protected void RadToolTipManager_OnAjaxUpdate(object sender, ToolTipUpdateEventArgs args)
        {
           UpdateToolTip(args.Value, args.UpdatePanel, Page);
        }

public void UpdateToolTip(string strVal, UpdatePanel panel, System.Web.UI.Page pg)
        {
            Control ctrl = pg.LoadControl("TooltipContainer.ascx");
            panel.ContentTemplateContainer.Controls.Add(ctrl);
            TooltipContainer details = (TooltipContainer)ctrl;

            if (strVal != "")
            {
                details.SetImage(strVal);
            }
        }

TooltipContainer markup:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TooltipContainer.ascx.cs" Inherits="TooltipContainer" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
 
<asp:Image runat="server" ID="TooltipImage" AlternateText="" Height="100%" Width="100%" BorderWidth="0"></asp:Image>

TooltipContainer Code-Behind (GetUrl function code omitted):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
using PL.BasePL;
 
    public partial class TooltipContainer : System.Web.UI.UserControl
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
          
        }
 
        public void SetImage(string strPath)
        {
 
          
            TooltipImage.ImageUrl = GetUrl(strPath);
         
 
        }
 
         
    }


TIA

11 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 01 Nov 2012, 12:01 PM
Hello Martin,

In order to export all the items even if they are collapsed you have to loop through all the detail tables and expand every item. Note that the hierarchy and the nested controls have a considerable effect on the performance in this scenario. Note that you have to make this loop OnItemCreated or OnItemDataBound event handler. For example:
bool isWordExport = false;
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.ExportToExcelCommandName)
        isExcelExport = true;
}
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (isExcelExport && e.Item.ItemIndex == 2)
    {
        foreach (GridDataItem mItem in RadGrid1.MasterTableView.Items)
        {
    mItem.Expanded = true;
    foreach (GridDataItem childItem in mItem.ChildItem.NestedTableViews(0).Items)
                   {
        childItem.Expanded = true;
                   }
         }
         RadGrid1.MasterTableView.ExportToExcel();
    }
}


Kind regards,
Kostadin
the Telerik team
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 their blog feed now.
0
Martin Roussel
Top achievements
Rank 1
answered on 01 Nov 2012, 05:30 PM
Hi Kostadin,

I think you misread my post since the two points im listing are issues (not what i want to achieve). In fact, for issue #1, I want to only export what is expanded (using <MasterTableView HierarchyLoadMode="Client">). It works fine for Excel and PDF but not MS Word.

Also, any idea for issue #2?
0
Kostadin
Telerik team
answered on 06 Nov 2012, 01:41 PM
Hi Martin,

I was not able to reproduce the issue. I prepared a small sample with a RadToolTip where only the expanded items are exported. Give it a try and let me how it differs from your real setup.

Regards,
Kostadin
the Telerik team
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 their blog feed now.
0
Martin Roussel
Top achievements
Rank 1
answered on 06 Nov 2012, 04:16 PM
Kostadin,

right from the start, Issue #1 is present in your sample (for me anyway). First thing I do after page is loaded (screen1.jpg), I expand nothing and click Export to Word which exports everything (screen2.pg), If I click then Export to PDF (screen3.jpg) or to Excel (screen4.jpg) only master rows are exported (since no rows are expanded in this scenario). If I then expand one row, Excel and PDF are only exporting that row (and its parent + the other non-expanded row) but Word always exports everything.

UPDATE: Ive modified your code to reproduce Issue #2. Ive also noticed that If I remove RadToolTipManager_OnAjaxUpdate, issue is gone (but i need this function to set my tooltip URL).

Markup:
<telerik:RadToolTipManager ID="RadToolTipManager1" runat="server" RelativeTo="Element"
        Position="MiddleRight" AutoTooltipify="true" ContentScrolling="Default" Width="150"
        Height="20" OnAjaxUpdate="RadToolTipManager_OnAjaxUpdate">
</telerik:RadToolTipManager>
 
<telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" runat="server" ShowStatusBar="True"
        ClientSettings-EnableRowHoverStyle="true" AutoGenerateColumns="False" PageSize="2"
        AllowSorting="True" AllowPaging="True" PagerStyle-Mode="NextPrevAndNumeric" GroupingSettings-CaseSensitive="false"
        PagerStyle-Position="Bottom" GridLines="Horizontal" Skin="WebBlue" CellSpacing="0" OnItemDataBound="RadGrid1_OnItemDataBound">
        <PagerStyle Mode="NumericPages"></PagerStyle>
        <MasterTableView DataSourceID="SqlDataSource1" DataKeyNames="CustomerID" AllowFilteringByColumn="true"
            EditFormSettings-EditColumn-Display="true" EditFormSettings-PopUpSettings-Modal="true"
            CurrentResetPageIndexAction="SetPageIndexToFirst" EditMode="PopUp" Width="100%"
            CommandItemDisplay="Top" HierarchyLoadMode="Client">
            <CommandItemSettings ShowExportToExcelButton="true" ShowExportToPdfButton="true"
                ShowExportToWordButton="true" />
            <DetailTables>
                <telerik:GridTableView DataKeyNames="OrderID" DataSourceID="SqlDataSource2" Width="100%" Name="Detail"
                    runat="server">
                    <ParentTableRelation>
                        <telerik:GridRelationFields DetailKeyField="CustomerID" MasterKeyField="CustomerID">
                        </telerik:GridRelationFields>
                    </ParentTableRelation>
                    <DetailTables>
                        <telerik:GridTableView DataKeyNames="OrderID" DataSourceID="SqlDataSource3" Width="100%"
                            runat="server" ToolTip="Table">
                            <ParentTableRelation>
                                <telerik:GridRelationFields DetailKeyField="OrderID" MasterKeyField="OrderID"></telerik:GridRelationFields>
                            </ParentTableRelation>
                            <Columns>
                                <telerik:GridBoundColumn SortExpression="UnitPrice" HeaderText="Unit Price" HeaderButtonType="TextButton"
                                    DataField="UnitPrice" UniqueName="UnitPrice">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn SortExpression="Quantity" HeaderText="Quantity" HeaderButtonType="TextButton"
                                    DataField="Quantity" UniqueName="Quantity">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn SortExpression="Discount" HeaderText="Discount" HeaderButtonType="TextButton"
                                    DataField="Discount" UniqueName="Discount">
                                </telerik:GridBoundColumn>
                            </Columns>
                            <SortExpressions>
                                <telerik:GridSortExpression FieldName="Quantity" SortOrder="Descending"></telerik:GridSortExpression>
                            </SortExpressions>
                        </telerik:GridTableView>
                    </DetailTables>
                    <Columns>
                        <telerik:GridBoundColumn SortExpression="OrderID" HeaderText="OrderID" HeaderButtonType="TextButton"
                            DataField="OrderID" UniqueName="OrderID">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn SortExpression="OrderDate" HeaderText="Date Ordered" HeaderButtonType="TextButton"
                            DataField="OrderDate" UniqueName="OrderDate" DataFormatString="{0:D}">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn SortExpression="Freight" HeaderText="Freight" HeaderButtonType="TextButton"
                            DataField="Freight" UniqueName="Freight">
                        </telerik:GridBoundColumn>
                    </Columns>
                    <SortExpressions>
                        <telerik:GridSortExpression FieldName="OrderDate"></telerik:GridSortExpression>
                    </SortExpressions>
                </telerik:GridTableView>
            </DetailTables>
            <Columns>
                <telerik:GridBoundColumn SortExpression="CustomerID" HeaderText="CustomerID" HeaderButtonType="TextButton"
                    DataField="CustomerID" UniqueName="CustomerID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn SortExpression="ContactName" HeaderText="Contact Name" HeaderButtonType="TextButton"
                    DataField="ContactName" UniqueName="ContactName">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn SortExpression="CompanyName" HeaderText="Company" HeaderButtonType="TextButton"
                    DataField="CompanyName" UniqueName="CompanyName">
                </telerik:GridBoundColumn>
            </Columns>
            <SortExpressions>
                <telerik:GridSortExpression FieldName="CompanyName"></telerik:GridSortExpression>
            </SortExpressions>
        </MasterTableView>
        <ExportSettings ExportOnlyData="true" OpenInNewWindow="true"
            HideStructureColumns="true">
            <Excel Format="Html"></Excel>
        </ExportSettings>
        <ClientSettings EnablePostBackOnRowClick="False" AllowRowsDragDrop="false" AllowDragToGroup="false"
            AllowColumnsReorder="false" ReorderColumnsOnClient="false" ColumnsReorderMethod="Reorder" AllowExpandCollapse="true">
            <Resizing AllowRowResize="False" EnableRealTimeResize="True" ResizeGridOnColumnResize="false"
                AllowColumnResize="true" AllowResizeToFit="true" />
            <Animation AllowColumnReorderAnimation="false" AllowColumnRevertAnimation="true" />
            <Selecting AllowRowSelect="true" />
            <ClientEvents OnRowClick="OnRowClick"></ClientEvents>
        </ClientSettings>
    </telerik:RadGrid>

Code-Behind:
protected void RadToolTipManager_OnAjaxUpdate(object sender, ToolTipUpdateEventArgs args)
    {
        //UpdateToolTip(args.Value, args.UpdatePanel, Page);
    }
 
    public void UpdateToolTip(string strVal, UpdatePanel panel, System.Web.UI.Page pg)
    {
        //Control ctrl = pg.LoadControl("TooltipContainer.ascx");
        //panel.ContentTemplateContainer.Controls.Add(ctrl);
        //TooltipContainer details = (TooltipContainer)ctrl;
 
        //if (strVal != "")
        //{
        //    details.SetImage(strVal);
        //}
    }
 
    protected void RadGrid1_OnItemDataBound(object sender, GridItemEventArgs e)
    {
 
        if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "Detail")
        {
            this.RadToolTipManager1.TargetControls.Add(e.Item.ClientID, "", true);
            
        }
 
    }


TIA
0
Kostadin
Telerik team
answered on 09 Nov 2012, 11:59 AM
Hello Martin,

I am afraid that we need more time to investigate the reason for this behavior. I will post the solution as soon as we have some progress. Please, excuse us for any inconvenience this might have caused you.

Kind regards,
Kostadin
the Telerik team
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 their blog feed now.
0
Martin Roussel
Top achievements
Rank 1
answered on 09 Nov 2012, 02:42 PM
Kostadin, Im confident that the Telerik team will find and fix those issues. Is it possible to be notified in this discussion (or in any other manner) when fixes are found? I would like to solve it asap.

Thanks again

Martin
0
Kostadin
Telerik team
answered on 14 Nov 2012, 12:32 PM
Hi Martin,

I already logged this as a bug in our tracking system and our developers will look into it. You could track the progress in our PITS.

Regards,
Kostadin
the Telerik team
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 their blog feed now.
0
Martin Roussel
Top achievements
Rank 1
answered on 04 Feb 2013, 08:46 PM
Kostadin,

Any update on these two bugs ive reported? Ive still experience them with Q3 2012 (1205). Also, ive noted that the PITS has it "Canceled". First, any reason why? and second, shouldnt I receive a notification email since I track this? I can almost swear ive never received anything.

I also remarked that the PITS only describe my issue #1. Dont we need to make another one for issue #2?

Please let me know,


Martin
0
Kostadin
Telerik team
answered on 07 Feb 2013, 11:58 AM
Hi Martin,

The first issue is already fixed and it will be available in Q1 2013. As to your second issue I suggest you to review the following help article.

Kind regards,
Kostadin
the Telerik team
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 their blog feed now.
0
Martin Roussel
Top achievements
Rank 1
answered on 07 Feb 2013, 03:27 PM
Kostadin,

For issue #1 - can you please explain why it is classified as "Canceled"? Im confused.

Issue #2 - the Toolltip displaying itself is not what I want to achieve (your link seem to document that). I want to be able to export the detail table expanded rows after tooltip has been generated.

TIA

Martin
0
Kostadin
Telerik team
answered on 12 Feb 2013, 12:47 PM
Hello Martin,

The reason this fix to be classified as "Canceled" is due to duplicated items in our system. It appears the item connected to our PITS was deleted instead the one which is not connected with it.
Your second question is already answered in the support ticket which you opened. I attached the project to this forum post if somebody else have the same issue as yours.

All the best,
Kostadin
the Telerik team
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 their blog feed now.
Tags
Grid
Asked by
Martin Roussel
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Martin Roussel
Top achievements
Rank 1
Share this question
or