Hi,
I am trying to format data dynamically, by allowing user to choose date format from context menu. The following is the event handler I use. When I debug I see that FlatDataSource is updated, but for some reason the grid is not updated. Could you please tell me what I am doing wrong. Or is this a bug?? Refreshing the grid doesn't seem to help.
private void QuickDates_Click(object sender, RoutedEventArgs e) { if (pivotGrid.DataSource != null) { MenuItem mi = sender as MenuItem; string dateFormat = mi.Header as string; FlatDataSource flatDataSource = pivotGrid.DataSource as FlatDataSource; int index = 0; foreach (DimensionMetadata metaData in flatDataSource.CubesSettings[0].DimensionSettings) { if (metaData.SourcePropertyName.Equals("End Date")) { flatDataSource.CubesSettings[0].DimensionSettings[index++].DisplayFormat = dateFormat; //metaData.DisplayFormat = dateFormat; break; } index++; } } }
Thanks
Sangeetha
Hello,
Currently such functionality is not supported and these settings are used only when the control is initialized.
Regards.Plamen.
Thank You Plamen.
Is there an alternative to this?
Hello Sangeetha,
I have been looking into your issue and there doesn’t seem to be a built-in functionality for that at this time. If you want I can create a Feature Request on your behalf so this can appear in a future release of ours.
Looking forward to hearing from you.
Hi Petar,
Why can't I use the approach in the following link where a Style is set for each cell and a converter is defined:
http://blogs.infragistics.com/forums/p/49331/297530.aspx
The only problem is, my converter does not seem to be working properly. Could you please tell me what I am doing wrong?
Here is my code:
My converter:
public class PivotGridDateConverter : IValueConverter { #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string formattedDate = ""; if (value != null) { try { IMember member = value as Member; DateTime dateTime = DateTime.Parse(member.Caption); formattedDate = dateTime.ToString("dd-MMM-yyyy"); } catch (Exception e) { Microsoft.Windows.Controls.MessageBox.Show(e.Message); } } return formattedDate; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return ""; } #endregion }
Here is the template I use in my style
<local:PivotGridDateConverter x:Key="DateConverter" /> <DataTemplate x:Key="DateTemplate" > <StackPanel Orientation="Horizontal"> <TextBlock Name="dateCellPresenter" Text="{Binding Converter={StaticResource DateConverter}}" /> </StackPanel> </DataTemplate>
Excuse me for the late reply. I have been looking into your issue for some time now and finally managed to come up with a custom approach that does what you want. I have put it into a sample project you can test out (PivotGrid_2.zip) where I have used a MultiValueConverter which would detect the different ContextMenu selections.
Please look through the sample and let me know if you require any further clarification on the matter.
My problem is, I set the Style in LayoutUpdated (as I need to set it only for a specific column), so when the Converter is executed, LayoutUpdated is fired again - so it goes into an infinite loop.
If I can find a better event to set the style in, my problem would be resolved.
Excuse me for the confusion I have spent some more time looking for a solution on your issue and think this I time I nailed it. I managed to use the CellControlAttached event to filter through the data cells and apply the formatting style from my previous sample only to those that meet a certain criteria. In the sample project I have created for you initially there are two measures loaded in the XamPivotGrid and I check and apply my Style only to the ones that come from the “Cost” measure. Also there is a ComboBox in the top right corner which SelectedItem sets a format for the “Cost” measure data cells dynamically thanks to a MultiBinding I used in the “CellStyle” style.
Please look through your sample project (PivotGrid_formatting_data.zip) and let me know if you require any further clarification on this custom approach.
Replacing IValueConverter with IMultiValueConverter did the trick. It works perfectly now.
Hi Sangeetha,
You can see how I have managed to get the format to come from the ComboBox in the top right corner through the binding in the sample I last sent. I used a MultiValueConverter in order to have a non-static format value. Now since the binging comes from it and from the cell values if there is a change in any of those the values are reconfigured.
Please let me know if you require any further clarification on the matter.
Thank You for your great solution. I used it to figure out what was wrong with mine - it works perfectly now. I had been setting the style to the PivotHeadercellControl instead of the PivotHeaderCell itself. Setting it to the PivotHeaderCell does not fire LayoutUpdated when the format is updated.
There is one other small thing that needs to be fixed. Right now I hardcode the format in the converter. I would like to set this format through the Converter's parameter. In other words I want to see the format coming through in the following function. How can I do this?
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{ }
Here is a new sample approach (PivotGrid_formatting_HeaderCells.zip). Please look into it and let me know if this is what you were looking for.
In the image below, I want to format the PivotHeaderCells in PivotHeaderColumn EndDate dynamically.