I am trying to use the xamPivotGrid for the first time, with a FlatDataSource based on a DataTable as described in another post (http://blogs.infragistics.com/forums/t/65463.aspx). One thing I cannot seem to get to work is the DisplayFormat for numeric columns. Here is the code excerpt that isn't working correctly:
var flatDataSource = new FlatDataSource()
{
ItemsSource = DataTableToList(dt),
Cube = DataSourceBase.GenerateInitialCube(dt.TableName),
DimensionsGenerationMode = DimensionsGenerationMode.Mixed
};
flatDataSource.Rows = DataSourceBase.GenerateInitialItems(groupByStr);
flatDataSource.Measures = DataSourceBase.GenerateInitialItems(measuresStr);
CubeMetadata cubeMetadata = new CubeMetadata();
flatDataSource.CubesSettings.Add(cubeMetadata);
foreach (DataColumn col in dt.Columns)
HierarchyDescriptor hier = new HierarchyDescriptor
SourcePropertyName = col.ColumnName,
HierarchyLevelDescriptor entriesLevel = new HierarchyLevelDescriptor
LevelName = col.ColumnName,
LevelExpressionPath = col.ColumnName
hier.LevelDescriptors.Add(entriesLevel);
flatDataSource.HierarchyDescriptors.Add(hier);
if (col.DataType == typeof(double))
DimensionMetadata dm = new DimensionMetadata()
DisplayName = col.ColumnName,
DimensionType = DimensionType.Measure,
AggregatorType = AggregatorType.Sum,
DisplayFormat = "{0:C2}"
cubeMetadata.DimensionSettings.Add(dm);
}
return flatDataSource;
figured it out - it was a simple matter of setting the correct DataTypeFullName on the CubeMetaData
Hi,
Glad you were able to find the solution. I created a sample with your code and we both came to the same conclusion.
I was just about to give you my sample with the DisplayTypeFullName and DisplayName added.
Could you please add your sample to this thread so I can see how you created the new measure?
I think that would give me a better idea how to answer your question.
I looked at Plamen's example, and its not exactly what I am after. I don't really need a custom aggregator, I just need to be able to definite a new measure by supplying a formula based on existing measures, e.g. a sum of two other measures. I actually took the code sample above from the CalculatedMembers example in Infragistics.Samples.WPF.xamFeatureBrowser.Samples.PivotGrid.Scenarios, but it doesn't seem to work for me.
I do see the new measure appear in the pivot (but not the selector), and the body of the pivot is empty - all calculations stop working. If I remove the new column, everything goes back to normal and I see all other measures being calculated.
There is a sample of in the WPF DataVisualization feature browser for the xamPivotGrid called Calculated Members which I think may be helpful. It in the Features List, on the Visual tab in the Display group.
It also looks like Plamen has a thread and a sample that should help you.
http://blogs.infragistics.com/forums/p/56695/290044.aspx
Let me know if you have any further questions.
Hi Marianne,
Thanks, I actually have a follow-up question on this. I am trying to create a calculated measure, following one of the examples. Basically after I build my FlatDataSource as above, I then do:
FlatDataSource fds = ...
ICalculatedItemViewModel calcMeasureViewModel =
new CalculatedMeasureViewModel(
"Net",
"Net MV",
"[Measures].[LongMV] + [Measures].[ShortMV]");
fds.Measures.Add(calcMeasureViewModel);
However, this doesn't seem to work - in fact, the pivot no longer shows any data and the calculated measure doesn't show up in the pivot selector. What am I missing?