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

Default format strings

7 Answers 408 Views
PivotGrid
This is a migrated thread and some comments may be shown as answers.
hamish
Top achievements
Rank 1
hamish asked on 17 Sep 2014, 08:45 PM
I am trying to set default format strings for the individual elements in the class I using as the item data source. . For the display name decorating the class element as follows, works just fine and the word Account appears in the field list as I would expect. However when I try and do the same thing for a default format as shown in the 2nd code snippet it does nothing. How do I set default format strings - thanks​
[Display(Name = "Account")]
 public string accnt { get; set;} 
[DisplayFormat(DataFormatString="#,##0.0000")]
 public double cnOpened { get; set; }

7 Answers, 1 is accepted

Sort by
0
Kalin
Telerik team
answered on 19 Sep 2014, 10:18 AM
Hello Hamish,

In order to achieve the desired you would need to set the desired StringFormat in the Xaml definition of the needed AggregateDescription as demonstrated below:

<pivot:PropertyAggregateDescription PropertyName="Quantity" StringFormat="#.#0" />

This will initially show the AggregateDescription with that format, however when modifing the Pivot at run time this format will be lost. So you would also need to hook to the PrepareDescriptionForField event of the provider in order to apply the format every time the fields in the FieldList are changed as shown below:

private void LocalDataSourceProvider_PrepareDescriptionForField(object sender, PrepareDescriptionForFieldEventArgs e)
{
    var aggregateDescription = e.Description as PropertyAggregateDescriptionBase;
  
    if (e.DescriptionType == Telerik.Pivot.Core.DataProviderDescriptionType.Aggregate && aggregateDescription != null && aggregateDescription.PropertyName == "Quantity")
    {
        aggregateDescription.StringFormat = "#.#0";
    }
}

Hope this helps.

Regards,
Kalin
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Brett
Top achievements
Rank 1
answered on 08 Dec 2015, 05:16 PM

Hi Kalin -

I would also like to setup default format strings for my aggregated values in my application. I am following the MVVM pattern, and am instantiating my LocalDataSourceProvider within the code of my view model. As a result, I cannot hook into the PrepareDescriptionForField event in my view's code-behind, but I understand I can use EventToCommandBehavior (http://docs.telerik.com/devtools/wpf/common-event-to-command-behavior.html) to setup a binding between the PrepareDescriptionForField event and a custom command in my view model to achieve this.

However, I am having trouble getting this to work. It seems the command is not firing when I make changes in my RadPivotFieldList. Can you offer an guidance or an example of wiring this up correctly?

My LocalDataSourceProvider is called CommissionDataProvider, and the relevant code snippet is shown here:

TestCommand = new RelayCommand(Test);
EventBinding eventBinding = new EventBinding();
eventBinding.Command = TestCommand;
eventBinding.EventName = "PrepareDescriptionForField";
eventBinding.RaiseOnHandledEvents = true;
eventBinding.PassEventArgsToCommand = true;
EventToCommandBehavior.GetEventBindings(CommissionDataProvider).Add(eventBinding);

Thanks,
Brett

0
Brett
Top achievements
Rank 1
answered on 09 Dec 2015, 03:40 PM

As a follow-up,

I have also changed my DataProvider binding to TwoWay, but that did not help either.

<pivot:RadPivotGrid Grid.Row="0" Grid.Column="0"
                    DataProvider="{Binding Path=CommissionDataProvider, Mode=TwoWay}"
                    telerikControls:StyleManager.Theme="Windows7"
                    HorizontalLayout="Tabular"
                    VerticalLayout="Compact"
                    RowSubTotalsPosition="Bottom"
                    RowGrandTotalsPosition="Bottom">
    <pivot:RadPivotGrid.RowGroupsExpandBehavior>
        <pivot:GroupsExpandBehavior Expanded="False" />
    </pivot:RadPivotGrid.RowGroupsExpandBehavior>
</pivot:RadPivotGrid>
 
<pivot:RadPivotFieldList Grid.Row="0" Grid.Column="1"
                         DataProvider="{Binding Path=CommissionDataProvider, Mode=TwoWay}"
                         telerikControls:StyleManager.Theme="Windows7" />

Any guidance?

Thanks,
Brett

0
Kalin
Telerik team
answered on 11 Dec 2015, 09:03 AM
Hi Brett,

The reason for the EventToCommandBehavior not working in this scenario is that the behavior is designed to work only with UIElements and the LocalDataSourceProvider inherits from DependencyObject. So I'm afraid you won't be able to use it in this particular scenario.

If you have any other questions, please let us know.

Regards,
Kalin
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
Brett
Top achievements
Rank 1
answered on 11 Dec 2015, 12:41 PM

Hi Kalin - 

Thank you for the reply. In this case, since I cannot use the EventToCommandBehavior functionality, what are my options for setting default format strings for the aggregate values, while still keeping the LocalDataSourceProvider in my view model? 

Thanks,
Brett

0
Kalin
Telerik team
answered on 15 Dec 2015, 09:03 AM
Hi Brett,

Since you have the LocalDataSourceProvider defined in the ViewModel, wouldn't be suitable for you to hook to the event directly there? If you don't want to use events in the ViewModel you could implement an attached behavior for the LocalDataSourceProvider and do the hooking there.

Hope this helps.

Regards,
Kalin
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
Brett
Top achievements
Rank 1
answered on 15 Dec 2015, 03:48 PM

Hi Kalin -

Thank you! As you suggested, I was able to simply add the event handler in the code of my view model.

CommissionDataProvider = new LocalDataSourceProvider();
CommissionDataProvider.PrepareDescriptionForField += CommissionDataProvider_PrepareDescriptionForField;

I appreciate the help.

Best,
Brett

Tags
PivotGrid
Asked by
hamish
Top achievements
Rank 1
Answers by
Kalin
Telerik team
Brett
Top achievements
Rank 1
Share this question
or