Completed
Last Updated: 28 Nov 2017 06:45 by ADMIN
ADMIN
Hristo
Created on: 14 Nov 2017 09:00
Category: PivotGrid
Type: Feature Request
1
IMPROVE. RadPivotGrid - expose API for modifying the default aggregate functions displayed in the AggregateOptionsDialog
The new API would allow some of the default functions to be removed and custom aggregate functions to be added. At the moment the dialog can be modified like this:

Public Class MyAggregateOptionsDialog
    Inherits AggregateOptionsDialog

    Private availableAggregateFunctions As IList(Of AggregateFunction) = New List(Of AggregateFunction)() From {
        AggregateFunctions.Sum,
        AggregateFunctions.Count,
        AggregateFunctions.Average,
        AggregateFunctions.Max,
        AggregateFunctions.Min,
        AggregateFunctions.Product,
        AggregateFunctions.StdDev,
        AggregateFunctions.StdDevP,
        AggregateFunctions.Var,
        AggregateFunctions.VarP,
        New SqrtSumAggregateFunction()
    }

    Public Overrides Sub LoadSettings(aggregateDescription As PropertyAggregateDescriptionBase)
        MyBase.LoadSettings(aggregateDescription)

        Dim listAggregateFunctions = DirectCast(Me.GetType().BaseType.GetField("listAggregateFunctions", BindingFlags.NonPublic Or BindingFlags.Instance).GetValue(Me), RadListControl)
        listAggregateFunctions.DataSource = availableAggregateFunctions
    End Sub
End Class
1 comment
ADMIN
Ralitsa
Posted on: 16 Nov 2017 11:17
Hello, 

In order to add a custom aggregate function in the AggregateOptionsDialog, you can use the code snippet below: 

public Form1()
{
    InitializeComponent();
    this.radPivotFieldList1.DialogsFactory = new MyPivotGridDialogsFactory();
}

public class MyAggregateOptionsDialog : AggregateOptionsDialog
{
    protected override IEnumerable<object> GetDefaultAggregateFunctions(AggregateDescriptionBase aggregateDescription)
    {
        base.GetDefaultAggregateFunctions(aggregateDescription).ToList().RemoveAt(2);

        IEnumerable<object> functions = base.GetDefaultAggregateFunctions(aggregateDescription);

        SqrtSumAggregateFunction sqrtSum = new SqrtSumAggregateFunction();
        IEnumerable<object> customFunctions = functions.Concat(new List<object> { sqrtSum });

        return customFunctions;
    }
}

public class MyPivotGridDialogsFactory : PivotGridDialogsFactory
{
    public override IAggregateOptionsDialog CreateAggregateOptionsDialog()
    {
        return new MyAggregateOptionsDialog();
    }
}

More information how to assign special aggregation functions which performing custom calculations can be found on the following link: https://docs.telerik.com/devtools/winforms/pivotgrid/custom-aggregation. 

Bear in mind, that the improvement will be available with our next release - R1 2018. 

Best regards, 
WinForms team