Posted 29 March 2023, 11: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]