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

[Solved] Hiding DetailTable Columns on Export

4 Answers 234 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 01 Feb 2010, 05:11 PM
I am trying to customize the look & feel when exporting a fairly complex RadGrid.  I have used several of the common techniques to either hide or swap out columns within the main (Master) table and those are working perfectly.  However, whenever I attempt to modify the look of the DetailTable, the changes are totally ignored... specifically:

1. The detail table shows the command row (Add New / Refresh) even though the MasterTable properly hides it (ExportOnlyData is set to True as is HideStructureColumns; these are set at the grid level, could not find any separate settings at the DetailTable level).

2. Setting the column visibility to False in code (during the ItemCommand) is not working for DetailTables, though it is working fine for the columns in the MasterTable.  Code below (removed some code, but not related to the column hiding; both columns ARE properly found and visibility set):

public void RadGrid_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) 
            RadGrid exportingGrid = source as RadGrid; 
 
            // only respond to the commands which invoke a built-in export 
            switch (e.CommandName) 
            { 
                case RadGrid.ExportToCsvCommandName: 
                case RadGrid.ExportToExcelCommandName: 
                case RadGrid.ExportToPdfCommandName: 
                case RadGrid.ExportToWordCommandName: 
             exportingGrid.MasterTableView.Columns.FindByUniqueName("CommandColDisplay").Visible = false
                        exportingGrid.MasterTableView.DetailTables[0].Columns.FindByUniqueName("DeptCommandColDisplay").Visible = false
                        break
 

Any insight or hints that anyone could provide would be greatly appreciated.
Adam

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 02 Feb 2010, 06:54 AM
Hi,

Try rebinding the grid after setting the visible property of the columns to false.

C#
 protected void btnExport_Click(object sender, EventArgs e) 
    { 
        RadGrid1.MasterTableView.DetailTables[0].Columns.FindByUniqueName("OrderDate").Visible = false
        RadGrid1.Rebind(); 
        RadGrid1.ExportSettings.OpenInNewWindow = true
        RadGrid1.ExportSettings.ExportOnlyData = true
        RadGrid1.MasterTableView.ExportToExcel(); 
    } 

Thanks,
Princy
0
Adam
Top achievements
Rank 1
answered on 18 Feb 2010, 11:06 PM
Princy:

I was finally able to get back on this project and apologize for the delay, but thank you for your suggestion.  Calling the Rebind() did fix one of the two issues in that it properly removed the command row from the export.  However, it did not fix the fact that the columns set to display="false" were still shown.

I have, however, seemed to run upon a work-around.  To hide the columns I was using code similar to:
ExportingGrid.MasterTableView.DetailTables[0].Columns.FindByUniqueName("ColName").Display = false


This is the non-working code.  However, if I operate directly on the OwnerTableView obtained from the command item arguments, I was able to set the display and have it properly hidden:

(e.Item as Telerik.Web.UI.GridCommandItem).OwnerTableView.Columns[0].Display = false


Is this an intended behavior and how I should be coding?  Note that the first scenario did not work even when that specific table was rebound with:
(e.Item as Telerik.Web.UI.GridCommandItem).OwnerTableView.Rebind(); 


Thanks again!
0
Accepted
Daniel
Telerik team
answered on 24 Feb 2010, 01:52 PM
Hello Adam,

The second code-snippet works as expected since you reference exactly that GridTableView that reside under the source item.

Actually you don't have to cast the item to GridCommandItem - you could access the OwnerTableView directly:
e.Item.OwnerTableView.Columns[0].Display = false;

An alternative approach could be to hide the column when the header item (for example) from the relevant GridTableView is created:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridHeaderItem && isExport)
        e.Item.OwnerTableView.GetColumn("column_name").Visible = false;
}

Please examine the following links for more information about the hierarchical structure:
Understanding hierarchical grid structure
Traversing detail tables/items in Telerik RadGrid

Kind regards,
Daniel
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Adam
Top achievements
Rank 1
answered on 25 Feb 2010, 02:10 PM
Daniel:

Thank you for your guidance and information regarding the ItemCreated event; utilizing this event to setup the column visibilities was our final solution and worked like a charm, even helping to fix an issue where the visibility of columns could be lost when multiple records were showing the detail table.

I appreciate both Telerik's and the community's help in solving this issue!

Adam
Tags
Grid
Asked by
Adam
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Adam
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or