Prevent the Export of Child Grid

4 posts, 0 answers
  1. Tim
    Tim avatar
    60 posts
    Member since:
    May 2011

    Posted 03 Feb 2012 Link to this post

    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();
     }








  2. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 07 Feb 2012 Link to this post

    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 >>
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Tim
    Tim avatar
    60 posts
    Member since:
    May 2011

    Posted 07 Feb 2012 Link to this post

    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;
    }



  5. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 10 Feb 2012 Link to this post

    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 >>
Back to Top