Completed
Last Updated: 14 Jun 2016 05:51 by ADMIN
ADMIN
Hristo
Created on: 09 Jun 2016 13:13
Category: PivotGrid
Type: Bug Report
0
FIX. RadPivotGrid - PivotGridSpread export does not export the row header if the column descriptions count is 0
How to reproduce:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_MouseDoubleClick(object sender, MouseEventArgs e)
    {
        PivotGridSpreadExport spreadExport = new PivotGridSpreadExport(this.radPivotGrid1);

        spreadExport.RunExport(@"..\..\exported-file.xlsx", new SpreadExportRenderer());
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        this.productsTableAdapter.Fill(this.nwindDataSet.Products);

        LocalDataSourceProvider dataProvider = new LocalDataSourceProvider();

        dataProvider.ItemsSource = nwindDataSet.Products;

        dataProvider.BeginInit();
        dataProvider.RowGroupDescriptions.Add(new PropertyGroupDescription() { PropertyName = "CategoryID", GroupComparer = new GroupNameComparer() });
        dataProvider.AggregateDescriptions.Add(new PropertyAggregateDescription() { PropertyName = "UnitPrice", AggregateFunction = AggregateFunctions.Sum });
        dataProvider.EndInit();

        this.radPivotGrid1.DataProvider = dataProvider;
    }
}


Workaround: create a custom pivot grid export object

 public partial class Form1 : Form
 {
     public Form1()
     {
         InitializeComponent();
     }

     private void Form1_MouseDoubleClick(object sender, MouseEventArgs e)
     {
         MyPivotGridSpreadExport spreadExport = new MyPivotGridSpreadExport(this.radPivotGrid1);

         spreadExport.RunExport(@"..\..\exported-file.xlsx", new SpreadExportRenderer());
     }

     private void Form1_Load(object sender, EventArgs e)
     {
         this.productsTableAdapter.Fill(this.nwindDataSet.Products);

         LocalDataSourceProvider dataProvider = new LocalDataSourceProvider();

         dataProvider.ItemsSource = nwindDataSet.Products;

         dataProvider.BeginInit();
         dataProvider.RowGroupDescriptions.Add(new PropertyGroupDescription() { PropertyName = "CategoryID", GroupComparer = new GroupNameComparer() });
         dataProvider.AggregateDescriptions.Add(new PropertyAggregateDescription() { PropertyName = "UnitPrice", AggregateFunction = AggregateFunctions.Sum });
         dataProvider.EndInit();

         this.radPivotGrid1.DataProvider = dataProvider;
     }
 }

public class MyPivotGridSpreadExport : PivotGridSpreadExport
{
    public MyPivotGridSpreadExport(RadPivotGrid pivotGrid)
        : base(pivotGrid) { }

    public override void Initialize()
    {
        base.Initialize();

        RadPivotGridElement pivotGrid = this.GetType().BaseType.GetField("pivotGrid", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this) as RadPivotGridElement;
        List<int> rowHeights = this.GetType().BaseType.GetField("rowHeights", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this) as List<int>;
        List<DescriptionBase> columnDescriptions = this.GetType().BaseType.GetField("columnDescriptions", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this) as List<DescriptionBase>;

        if (columnDescriptions.Count == 0)
        {
            rowHeights.Add(pivotGrid.RowHeight);
            columnDescriptions.Add(null);
        }
    }
}
0 comments