In using the different aggregator factories is there a method or override that will allow for defining a custom name for the return label. For example, calling the SumAggregatoryFactory to sum the "Amount" field will return a row label of "Sum of Amount". What if instead we wanted it to be "Total Amount", "Total" or some other custom value?
Asked
Active
Viewed 130 times
2 Answers
0
Create a ResultAmount class. That will return a description of the result, not the string. Something like this:
class ResultAmount
{
public string Label { get; set; }
public decimal SumAmount { get; set; }
public override string ToString()
{
return $"{Label}: {SumAmount}";
}
}
For different factories, the Label value may be different. Then you have a factory:
class TotalCalculations
{
public ResultAmount SumAggregatoryFactory()
{
return new ResultAmount
{
Label = "Total",
SumAmount = 100
};
}
}
And the point of calling factory:
class BillingService
{
public void Print(TotalCalculations calc)
{
//when calling the method, you can use the standard Label
string original = calc.SumAggregatoryFactory().ToString();
//or take only the sum and configure the result string yourself
string custom = $"My message: {calc.SumAggregatoryFactory().SumAmount}";
}
}

zsender
- 21
- 3
0
If you use PivotData Toolkit writers (like PivotTableHtmlWriter
) you can customize measure labels as you with FormatMeasureHeader property:
pvtHtmlWr.FormatMeasureHeader = (aggrFactory, measureIndex) => {
// customize header by factory type or measure index
return aggrFactory.ToString();
};
(see also: https://www.nrecosite.com/pivotdata/format-pivot-table.aspx).
In case of custom rendering you can define your own formatting of measure names that takes into account aggregator type.

Vitaliy Fedorchenko
- 8,447
- 3
- 37
- 34