Custom Aggregates

Posted by: grapecity on 11 July 2022, 11:17 pm EST

  • Posted 11 July 2022, 11:17 pm EST

    Hi,

    I am still evaluating C1 Blazor, and I remember whilst having had the trial license, I was not able to find any documentation on how FlexGrid’s GridAggregate.Custom is used (e.g. to display a weighted average).

    Are there meanwhile any pointers you could share so I can make sure we would not run into problems, if we were to pick C1?

    Thank you,

    Esther

  • Posted 14 July 2022, 10:29 pm EST

    Hi Esther,

    We are sorry for the inconvenience but we are unable to find the corresponding property for this so we have forwarded this to the concerned team for further investigation with the internal tracking id C1-4742.

    We will let you know as we get an update on this.

    Regards,

    Manish Gupta

  • Posted 29 March 2023, 2:20 pm EST

    The GridAggregate.Custom property allows you to define a custom aggregate function for a specific column in the FlexGrid. Here are the example:

    [code]// Define the custom aggregate function

    public double WeightedAverage(IEnumerable items)

    {

    double sum = 0;

    double weightSum = 0;

    foreach (var item in items)
    {
        double value = Convert.ToDouble(item);
    
        // Get the weight from another column in the same row
        double weight = Convert.ToDouble((item as IDictionary<string, object>)["WeightColumn"]);
    
        sum += value * weight;
        weightSum += weight;
    }
    
    if (weightSum == 0)
        return 0;
    
    return sum / weightSum;
    

    }

    // Assign the custom aggregate function to a GridAggregate object

    var customAggregate = new GridAggregate

    {

    Custom = WeightedAverage contexto

    };

    // Assign the GridAggregate object to the Aggregate property of the column you want to apply the custom aggregate to

    flexGrid.Columns[“ValueColumn”].Aggregate = customAggregate;[/code]

  • Posted 30 March 2023, 2:21 am EST

    Has this code also been tested with blazor wasm?

    Our developers run into compiler errors, when trying to use your example:

    • component parameter ‘Aggregate’ should not be set outside of its component, or
    • Static member ‘Custom’ cannot be initialized in an object initializer.

    Using latest version (6.0.20231.491).

  • Posted 30 March 2023, 6:13 am EST

    Hi,

    This issue is still with the Development team and they do not have any ETA for now. The code shared by sechanyang3210 seems SPAM post. Please ignore that.

    Regards,

    Manish Gupta

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels