I have a RadGrid with 2 levels of data hierarchy (Countries > Campaigns > Entries) . I only want to export the lowest level grid (Entries) to Excel.
For some reason, the Export isn't happening. The ItemCommand event with the CampaignsRadGrid.MasterTableView.ExportToExcel(); call is being hit though, but the only thing that happens is that the pagination controls, on the bottom of the grid, disappear.
ASPX code:
<
telerik:RadAjaxManagerProxy
ID
=
"RadAjaxManager1"
runat
=
"server"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"CampaignsRadGrid"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"CampaignsRadGrid"
LoadingPanelID
=
"RadAjaxLoadingPanel1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManagerProxy
>
<
telerik:RadAjaxLoadingPanel
ID
=
"RadAjaxLoadingPanel1"
runat
=
"server"
Skin
=
"Vista"
></
telerik:RadAjaxLoadingPanel
>
<
telerik:RadGrid
ID
=
"CampaignsRadGrid"
Width
=
"97%"
Skin
=
"Office2007"
AllowPaging
=
"True"
PageSize
=
"10"
runat
=
"server"
AllowSorting
=
"true"
AutoGenerateColumns
=
"false"
GridLines
=
"None"
onneeddatasource
=
"CampaignsRadGrid_NeedDataSource"
ondetailtabledatabind
=
"CampaignsRadGrid_DetailTableDataBind"
onitemcommand
=
"CampaignsRadGrid_ItemCommand"
>
<
PagerStyle
Mode
=
"NextPrevNumericAndAdvanced"
AlwaysVisible
=
"true"
/>
<
MasterTableView
Width
=
"100%"
EditMode
=
"PopUp"
DataKeyNames
=
"ID"
AllowMultiColumnSorting
=
"True"
>
<
DetailTables
>
<
telerik:GridTableView
DataKeyNames
=
"ID"
Name
=
"Campaigns"
Width
=
"100%"
NoDetailRecordsText
=
"There are no campaigns for this country."
>
<
DetailTables
>
<
telerik:GridTableView
CommandItemDisplay
=
"Top"
DataKeyNames
=
"ID"
AutoGenerateColumns
=
"true"
Name
=
"Entries"
NoDetailRecordsText
=
"There are no entries for this campaign."
Width
=
"100%"
>
<
CommandItemSettings
ShowExportToExcelButton
=
"true"
ShowRefreshButton
=
"false"
ShowAddNewRecordButton
=
"false"
/>
</
telerik:GridTableView
>
</
DetailTables
>
<
Columns
>
<
telerik:GridBoundColumn
UniqueName
=
"CampaignName"
DataField
=
"CampaignName"
SortExpression
=
"CampaignName"
HeaderText
=
"Campaign Name"
AllowSorting
=
"true"
/>
<
telerik:GridDateTimeColumn
UniqueName
=
"DateCreated"
SortExpression
=
"DateCreated"
DataField
=
"DateCreated"
HeaderText
=
"Date Created"
DataFormatString
=
"{0:d}"
AllowSorting
=
"true"
/>
<
telerik:GridBoundColumn
UniqueName
=
"Entries"
SortExpression
=
"Entries"
DataField
=
"Entries"
HeaderText
=
"Entries"
AllowSorting
=
"true"
/>
</
Columns
>
</
telerik:GridTableView
>
</
DetailTables
>
<
Columns
>
<
telerik:GridBoundColumn
UniqueName
=
"CountryName"
SortExpression
=
"CountryName"
DataField
=
"CountryName"
HeaderText
=
"CountryName"
AllowSorting
=
"true"
/>
</
Columns
>
</
MasterTableView
>
<
ClientSettings
EnableRowHoverStyle
=
"true"
/>
<
PagerStyle
Mode
=
"NextPrevAndNumeric"
/>
</
telerik:RadGrid
>
C# code:
protected
void
CampaignsRadGrid_ItemCommand(
object
source, GridCommandEventArgs e)
{
if
(e.CommandName == Telerik.Web.UI.RadGrid.ExportToExcelCommandName)
{
ConfigureExport();
CampaignsRadGrid.MasterTableView.ExportToExcel();
}
}
public
void
ConfigureExport()
{
CampaignsRadGrid.ExportSettings.ExportOnlyData =
true
;
CampaignsRadGrid.ExportSettings.IgnorePaging =
true
;
CampaignsRadGrid.ExportSettings.OpenInNewWindow =
false
;
}
Any thoughts? Thanks in advance for any help...
13 Answers, 1 is accepted
![](/forums/images/avatarimages/default.gif)
Try to use the below code to make it functioning. Hope it may help
<
script
type
=
"text/javascript"
language
=
"javascript"
>
function onRequestStart(sender, args) {
if (args.get_eventTarget().indexOf("ExportToExcelButton") >= 0 ||
args.get_eventTarget().indexOf("ExportToPdfButton") >= 0) {
args.set_enableAjax(false);
}
}
</
script
>
<
telerik:RadAjaxManager
ID
=
"radAjaxManager"
runat
=
"server"
>
<
ClientEvents
OnRequestStart
=
"onRequestStart"
/>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadSummary"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadSummary"
LoadingPanelID
=
"RadAjaxLoadingPanel1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
-Thanx
![](/forums/images/avatarimages/default.gif)
Unfortunately I get the same result, but with javascript error:
Sys.InvalidOperationException: A control is already
associated with the element.
Firebug pointed the error to this functionSys.UI.Control =
function
Sys$UI$Control(element) {
/// <summary locid="M:J#Sys.UI.Control.#ctor" />
/// <param name="element" domElement="true"></param>
var
e = Function._validateParams(arguments, [
{name:
"element"
, domElement:
true
}
]);
if
(e)
throw
e;
if
(
typeof
(element.control) !=
'undefined'
)
throw
Error.invalidOperation(Sys.Res.controlAlreadyDefined);
Sys.UI.Control.initializeBase(
this
);
this
._element = element;
element.control =
this
;
}
![](/forums/images/avatarimages/default.gif)
Removed this and the export works. only problem is that it seems to be exporting the master table's data, but with the detail table's fields. because the only common field between these two is "ID" that is the only column that contains data (in the exported Excel file).
Is it necessary to do a Rebind() or something similar? or should I be targeting the DetailTable when calling the ExportToExcel() method?
i.e.
CampaignsRadGrid.MasterTableView.DetailTables[0].DetailTables[0].ExportToExcel();
instead of
CampaignsRadGrid.MasterTableView.ExportToExcel();
I'll try a few things and if I find a solution myself, I'll put it up here...
![](/forums/images/avatarimages/default.gif)
CampaignsRadGrid.ExportSettings.IgnorePaging =
true
;
setting IgnorePaging = false fixed my problem.
see here: http://www.telerik.com/community/forums/aspnet-ajax/grid/export-multi-level-hierarchy-radgrid.aspx#920000
![](/forums/images/avatarimages/default.gif)
In the Hierarchical Table I set Display="false" on certain columns to show a 'summary' of the data. No matter what I try, I cannot get those columns to export to Excel - it only ever exports the visible ones.
Grid:
<
Columns
>
<
telerik:GridBoundColumn
Display
=
"false"
UniqueName
=
"ID"
DataField
=
"ID"
SortExpression
=
"ID"
HeaderText
=
"ID"
AllowSorting
=
"true"
/>
<
telerik:GridBoundColumn
Display
=
"false"
UniqueName
=
"CampaignName"
DataField
=
"CampaignName"
SortExpression
=
"CampaignName"
HeaderText
=
"CampaignName"
AllowSorting
=
"true"
/>
<
telerik:GridDateTimeColumn
UniqueName
=
"DateCreated"
SortExpression
=
"DateCreated"
DataField
=
"DateCreated"
HeaderText
=
"Date Created"
DataFormatString
=
"{0:d}"
AllowSorting
=
"true"
/>
<
telerik:GridDateTimeColumn
Display
=
"false"
UniqueName
=
"DOB"
SortExpression
=
"DOB"
DataField
=
"DOB"
HeaderText
=
"DOB"
DataFormatString
=
"{0:d}"
AllowSorting
=
"true"
/>
<
telerik:GridBoundColumn
Display
=
"false"
UniqueName
=
"VariableField1"
SortExpression
=
"VariableField1"
DataField
=
"VariableField1"
HeaderText
=
"VariableField1"
AllowSorting
=
"true"
/>
</
Columns
>
C#
GridTableView detailsTable = (GridTableView)CampaignsRadGrid.MasterTableView.DetailTables[0].DetailTables[0];
//foreach (GridColumn c in detailsTable.Columns)
//{
// c.Display = true;
//}
GridColumn test = CampaignsRadGrid.MasterTableView.DetailTables[0].DetailTables[0].GetColumn(
"ID"
);
test.Display =
true
;
//CampaignsRadGrid.MasterTableView.GetColumn("VariableField1").Display = true;
CampaignsRadGrid.Rebind();
CampaignsRadGrid.ExportSettings.ExportOnlyData =
true
;
CampaignsRadGrid.ExportSettings.IgnorePaging =
false
;
CampaignsRadGrid.ExportSettings.OpenInNewWindow =
false
;
any ideas on what to do to make those columns display in the Export?
![](/forums/images/avatarimages/default.gif)
protected
void
rgUserListing_ItemCommand(
object
source, GridCommandEventArgs e)
{
if
(e.CommandName ==
"ExportToExcel"
)
{
rgUserListing.ExportSettings.FileName =
"UserList"
+ DateTime.Now.ToString(
"-dd-MM-yyyy"
);
foreach
(GridColumn col
in
rgUserListing.MasterTableView.Columns)
col.Visible =
true
;
}
}
![](/forums/images/avatarimages/default.gif)
I had already tried marking the columns as Visible=true and Display=true, but to no avail.
In the end, I used a separate temporary (hidden) RadGrid for the export. Not ideal and not the most efficient solution, but time was against me...
You can try to traverse the columns recursively:
void
ShowAllColumns(GridTableView gridTableView)
{
foreach
(GridNestedViewItem nestedViewItem
in
gridTableView.GetItems(GridItemType.NestedView))
{
if
(nestedViewItem.NestedTableViews.Length > 0)
{
foreach
(GridColumn column
in
gridTableView.Columns)
column.Display =
true
;
ShowAllColumns(nestedViewItem.NestedTableViews[0]);
}
}
}
protected
void
Button1_Click(
object
sender, EventArgs e)
{
ShowAllColumns(RadGrid1.MasterTableView);
RadGrid1.MasterTableView.ExportToExcel();
}
Regards,
Daniel
the Telerik team
![](/forums/images/avatarimages/default.gif)
Dear Adam,
kindly your advice about export detail table as you made before, just i want to know how to disable paging in detail table to export data when expand one record of main radgrid
![](/forums/images/avatarimages/default.gif)
Sorry dear, but in other word i want to do the following:
When clicking export in the detail table, export all records of the detail table (for that master table record).
any way to do that please
Exporting separate table views is not recommended and might not work as expected. The export buttons are working this way only because we would like to avoid breaking changes.
That said, if you let me know which export format is used in your project I may have a suggestion for that particular case.
Regards,
Daniel
Telerik
![](/forums/images/avatarimages/default.gif)
hello Daniel,
i want to export the data into csv file, i use the same way that used in the first post of this conversation that introduce the way of exporting detail table for one record of grid that we expand and if detail table for that records takes more than one page i can't export all pages in detail table for one record of detail table that we expanded, but i can export only one page of that detail table.
please help me, just i want to export data of record from hierarchical radgrid that we expanded to csv file
You can try the following approach:
protected
void
RadGrid1_ItemCommand(
object
sender, GridCommandEventArgs e)
{
if
(e.CommandName == RadGrid.ExportToCsvCommandName)
{
RadGrid1.ExportSettings.IgnorePaging =
false
;
e.Item.OwnerTableView.AllowPaging =
false
;
e.Item.OwnerTableView.Rebind();
}
}
I hope this helps.
Regards,
Daniel
Telerik