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

Prevent the Export of Child Grid

3 Answers 45 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 2
Tim asked on 03 Feb 2012, 05:46 PM
I have a hierarchical Radgrid
Batch...
        Adjustments...
                         Comments
I have the functionality of export to excel on the 'Adjustments' grid. How can I prevent the export of the 'Comments' grid if the user clicks Export when Comments are expanded?

protected void ConfigureExport(object source, GridCommandEventArgs e)
 {
     e.Item.OwnerTableView.GetColumn("PolicyEditRecord").Visible = false;
     e.Item.OwnerTableView.GetColumn("DeleteTransaction").Visible = false;
     e.Item.OwnerTableView.GetColumn("ManualAdjustmentBatchID").Visible = false;
     e.Item.OwnerTableView.GetColumn("ManualAdjustmentID").Visible = false;
     ((RadGrid)source).ExportSettings.ExportOnlyData = true;
     ((RadGrid)source).ExportSettings.IgnorePaging = true;
     ((RadGrid)source).ExportSettings.OpenInNewWindow = false;
     ((RadGrid)source).ExportSettings.HideStructureColumns = true;
     ((RadGrid)source).MasterTableView.HierarchyDefaultExpanded = false;
     ((RadGrid)source).MasterTableView.ExportToExcel();
 }








3 Answers, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 07 Feb 2012, 05:07 PM
Hello,

Please examine the Export Hierarchical Grid demo to see how the desired functionality can be implemented.

I hope this helps.

All the best,
Mira
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Tim
Top achievements
Rank 2
answered on 07 Feb 2012, 10:14 PM
Thanks for the pointer Mira,
Because I was already implementing some RadGrid state management to preserve the RadGrid on postback I found that implementing in this manner worked just like I needed it to except for it removes my column headers. Why would it do that?

I call this from my class with the RadGrid
switch (e.CommandName)
{
    case RadGrid.ExportToExcelCommandName:
        ExpandAllDetailTableRecords(source, ExpandedStates, false);
        ConfigureExport(source, e);
        break;
}

and execute the method in the base class. That way all of my RadGrids will be able to take advantage of the same process

/// <summary>
/// Set the Expanded state for all detail table records.
/// </summary>
/// <param name="source">The source.</param>
/// <param name="expandedStates">The expanded states.</param>
/// <param name="expanded">if set to <c>true</c> [expanded].</param>
/// <remarks></remarks>
protected static void ExpandAllDetailTableRecords(object source, Hashtable expandedStates, bool expanded)
{
    string[] indexes = new string[expandedStates.Keys.Count];
    expandedStates.Keys.CopyTo(indexes, 0);
    ArrayList arr = new ArrayList(indexes);
    arr.Sort();
    foreach (string key in from string key in arr let value = (bool)expandedStates[key] where value select key)
    {
        ((RadGrid)source).Items[key].Expanded = expanded;
    }
}


*** EDIT ***
It appears that arr[0] contains that header columns and you can collaps that row eventhough it is not a member of an expandable row. Adding this check (where key != "0") to the code solved the problem.

foreach (string key in from string key in arr where key != "0" let value = (bool)expandedStates[key] where value select key)
{
    ((RadGrid)source).Items[key].Expanded = expanded;
}



0
Mira
Telerik team
answered on 10 Feb 2012, 02:22 PM
Hello Tim,

I am glad that the issue is resolved.

Thank you for sharing the solution with the community.

All the best,
Mira
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
Grid
Asked by
Tim
Top achievements
Rank 2
Answers by
Mira
Telerik team
Tim
Top achievements
Rank 2
Share this question
or