This is a migrated thread and some comments may be shown as answers.

Show string property for items

3 Answers 82 Views
PivotGrid and PivotFieldList
This is a migrated thread and some comments may be shown as answers.
Jens
Top achievements
Rank 1
Jens asked on 29 Sep 2015, 12:16 PM

Hey,

the data i'm aggregating contains a string value (eg. country) for each item.

I want to display the string value in the PivotGrid as followed:

There should be a column "Country" and the grouped items should display an empty string (since i see no good way to aggregate strings except maybe concatenating). When i open up the groups and drill down to a specific item, the "Country" column should display the country value for the item.

Is there any way to achive this?

Cheers,

Jens

3 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 30 Sep 2015, 03:49 PM
Hello Jens,

Thank you for writing.

You can modify the displayed text in cells in RadPivotGrid by subscribing to the CellFormatting event and in the handler perform the required validation and where needed set the text to an empty string:
private void radPivotGrid1_CellFormatting(object sender, PivotCellEventArgs e)
{
    if (e.CellElement.AggregateDescription.DisplayName == "Country")
    {
        e.CellElement.Text = "";
    }
    else
    {
        e.CellElement.ResetValue(LightVisualElement.TextProperty, ValueResetFlags.Local);
    }
}

Additional information is available in the following documentation article: Formatting Appearance.

I hope this helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo Merdjanov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Jens
Top achievements
Rank 1
answered on 01 Oct 2015, 07:44 AM

Hey,

thanks Hristo, but my problem is not about formatting, it's about aggregating strings.

I've solved my problem with a custom aggregator.

01.public class StringAggregateFunction : AggregateFunction
02.{
03.    protected override Cloneable CreateInstanceCore()
04.    {
05.        return new StringAggregateFunction();
06.    }
07. 
08.    protected override void CloneCore(Cloneable source)
09.    { }
10. 
11.    public override string DisplayName
12.    {
13.        get { return "StringAggregateFunction"; }
14.    }
15. 
16.    protected override AggregateValue CreateAggregate(IAggregateContext context)
17.    {
18.        return new StringAggregate();
19.    }
20.}
21. 
22.public class StringAggregate : AggregateValue
23.{
24.    private string value = String.Empty;
25. 
26.    protected override object GetValueOverride()
27.    {
28.        return value;
29.    }
30. 
31.    protected override void AccumulateOverride(object value)
32.    {
33.        // only set value the first time
34.        if (this.value == String.Empty)
35.        {
36.            this.value = Convert.ToString(value);
37.        }
38. 
39.        //this.value = this.value + Convert.ToString(value);
40.    }
41. 
42.    protected override void MergeOverride(AggregateValue childAggregate)
43.    {
44.        var stringAggregate = childAggregate as StringAggregate;
45.        if (stringAggregate != null)
46.        {
47.            if (this.value == String.Empty)
48.            {
49.                // first aggregation value
50.                this.value = stringAggregate.value;
51.            }
52.            else if (this.value != stringAggregate.value)
53.            {
54.                // next aggregation differs
55.                this.value = "Mixed";
56.            }
57.            else
58.            {
59.                // next aggregation value is the same
60.            }
61.        }
62.        else
63.        {
64.            throw new InvalidOperationException();
65.        }
66.    }
67.}

Cheers,

Jens

0
Hristo
Telerik team
answered on 02 Oct 2015, 02:53 PM
Hello Jens,

Thank you for writing back.

Please excuse me for the misunderstanding. I confirm that the solution with the custom aggregate is valid and should bring the desired result.

Should you have further questions please do not hesitate to write back.

Regards,
Hristo Merdjanov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
PivotGrid and PivotFieldList
Asked by
Jens
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Jens
Top achievements
Rank 1
Share this question
or