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

How to customize StringFormat according to columns/rows

4 Answers 78 Views
PivotGrid
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Iron
Thomas asked on 22 Oct 2018, 10:01 AM

Hello,

 

I work with version 2016 R3.

 

I have a series of Data like this

DataType | DataPoint | Value

I displayed correctly all values with either DataType and DataPoint in column or row

 

Now I want to use different string format according to which DataType it corresponds.

I found the StringFormatSelector on the PropertyAggregateDescription and I thought I could use it like any [...]Selector but I don't have in input of the SelectStringFormat method the CellAggregateValue associated.

 

For now the only way to do that is by using a converter on the CellTemplateSelector of the PivotGrid

(I'm currently implementing it, it's not working as expected yet)

 

Is there a best way to achieve different string format according to a celldata ?

 

Regards

Thomas

 

4 Answers, 1 is accepted

Sort by
0
Thomas
Top achievements
Rank 1
Iron
answered on 24 Oct 2018, 09:46 AM

Hello

Here is an update with my tests

The solution with a converter in the CellTemplateSelector is working but only for to display values in the PivotGrid.

 

If I export the PivotGrid in Excel it doesn't work.

 

So I think the StringFormatSelector of the PropertyAggregateDescription is the solution but how can I use it ?

 

Thank you

Regards,

Thomas

0
Dinko
Telerik team
answered on 25 Oct 2018, 09:19 AM
Hi Thomas,

The StringFormatSelector class doesn't provide functionality to check the current cell value which is applied. Overriding the SelectStringFormat() method will return one format for all cell values in the specified PropertyAggregateDescription. The SelectStringFormat() can be used the following way.
<pivot:PropertyAggregateDescription PropertyName="Net"   >
    <pivot:PropertyAggregateDescription.StringFormatSelector>
        <local:MyStringFormatSelector PropertyName="Net" />
    </pivot:PropertyAggregateDescription.StringFormatSelector>                 
</pivot:PropertyAggregateDescription>
 
<pivot:PropertyAggregateDescription PropertyName="Quantity" >
    <pivot:PropertyAggregateDescription.StringFormatSelector>
        <local:MyStringFormatSelector  PropertyName="Quantity" />
    </pivot:PropertyAggregateDescription.StringFormatSelector>
</pivot:PropertyAggregateDescription>

public class MyStringFormatSelector : StringFormatSelector
{
    public string PropertyName { get; set; }
    protected override string SelectStringFormat()
    {
        if(PropertyName == "Net")
        {
            return "$$#.###";
        }
        else
        {
            return "**#.###";
        }          
    }
 
    protected override void CloneCore(Cloneable source)
    {
        var original = (MyStringFormatSelector)source;
        this.PropertyName = original.PropertyName;
    }
 
    protected override Cloneable CreateInstanceCore()
    {
        return new MyStringFormatSelector();
    }
}

Regards,
Dinko
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Thomas
Top achievements
Rank 1
Iron
answered on 25 Oct 2018, 02:28 PM

Hello,

 

Thank you for you reply

 

We found a better solution that works for the display, the excel export and the Copy/Paste feature

 

We added in our data a new property that represent the value formatted as a string

DataType | DataPoint | Value | ValueFormatted

 

Then because we only have 1 value for the rows and columns, we specified an AggregateFunction that return directly the object read from the our dataSource (here our string formatted) with this code below and a custom AggregateFunction using this AggregateValue

 

public class ValueAggregate : AggregateValue
{
    private object _value;
 
    protected override object GetValueOverride()
    {
        return _value;
    }
 
    protected override void AccumulateOverride(object value)
    {
        _value = value;
    }
 
    protected override void MergeOverride(AggregateValue childAggregate)
    {
    }
}

 

Then everything works as planned.

 

We couldn't use the StringFormatSelector because we only had one PropertyAggregateDescription for different string format.

 

Thank you.

Hervouet Thomas

0
Dinko
Telerik team
answered on 26 Oct 2018, 12:29 PM
Hello Thomas,

I am happy to hear that you have found a solution which fits in your main application. And thank you for sharing it. This way the community can benefit from it.

Regards,
Dinko
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
PivotGrid
Asked by
Thomas
Top achievements
Rank 1
Iron
Answers by
Thomas
Top achievements
Rank 1
Iron
Dinko
Telerik team
Share this question
or