Hi,
I'd like to ask if it is possible to change the captions of the measures/dimensions generated automatically by a flatdatasource (based on an IEnumerable)? So if the flatDataSource.ItemsSource is set to an IEnumerable and the captions are like "PRDGRP" and "ST_DATE" by default, then I'd like to display them in the dataselector as "Product Group" and "Start date". Is it possible to change the captions of the items in the data selector?
Thanks and best regards,
Tamas
Hi Tamas,
You can decorate the properties of your business objects’ class with DisplayAttribute and set its Name property and this value will be displayed in the UI of the pivot grid.
[DisplayAttribute(Name = "Product Group")]
public string ProductGroup
{
get;
set;
}
Note that there is an option also to set display format for the measures. In this case you set DisplayFormatAttribute:
[DisplayFormat(DataFormatString = "{0:C2}")]
public double Cost
If you want to do that within XAML you have to add a new CubeMetadata object to FlatDataSource.CubeSettings collection and then have to add DimensionMetadata object for each property:
<!—Overrides the default meta attributes -->
<FlatData:FlatDataSource.CubesSettings>
<FlatData:CubeMetadata DataTypeFullName="[Your data type full name]" DisplayName="[The UI name of the cube]">
<FlatData:DimensionMetadata SourcePropertyName="ProductGroup" DisplayName="Product Group"/>
</FlatData:CubeMetadata>
</FlatData:FlatDataSource.CubesSettings>
I hope that covers your needs.
Regards.
PPilev.
Hi Plamen,
Since the business objects are not known during design time, I would need this during runtime. Here is my code, but it does not work:
public FlatDataSource CreateDataSource(List<Dictionary<object, object>> list, ObservableCollection<string> texts) { FlatDataSource flatDataSource = new FlatDataSource();
// this creates an IEnumerable from the list<dictionary<object,object>>
flatData = DataSourceCreator.ToDataSource(list); flatDataSource.ItemsSource = flatData; CubeMetadata csettings = new CubeMetadata { DataTypeFullName = flatData.GetType().ToString(), DisplayName = "DisplayNameXYZ" };
// go through the first dictionary to get the property names from the keys
int i = 0; foreach (KeyValuePair<object, object> pair in list[0]) { DimensionMetadata dm = new DimensionMetadata(); dm.DisplayName = texts[i]; dm.SourcePropertyName = pair.Key.ToString(); csettings.DimensionSettings.Add(dm); i++; } flatDataSource.CubesSettings.Add(csettings);
...
The name of the cube is still equal to the name of the type and the texts are still equal to the field names. What do I do wrong?
Many thanks and best regards,
Tamás
Unfortunately if I add this to the end then I got an error at this line,
flatDataSource.CubesSettings.Add(csettings);
because flatDataSource.CubesSettings is null. I cannot create it,
flatDataSource.CubesSettings = new List<CubeMetadata>();
since it is read only.
Ok,
Try to initalize FlatDataSource in thos way:
FlatDataConnectionSettings flatDataSettings =
new FlatDataConnectionSettings();
FlatDataSource flatDataSource =
new FlatDataSource
ConnectionSettings = flatDataSettings
};
Now it does not give an error, but the texts are still not changed. Here is my code:
CubeMetadata csettings = new CubeMetadata { DataTypeFullName = flatData.GetType().ToString(), DisplayName = "DisplayNameXYZ" }; int i = 0; foreach (KeyValuePair<object, object> pair in list[0]) { DimensionMetadata dm = new DimensionMetadata(); dm.DisplayName = texts[i]; dm.SourcePropertyName = pair.Key.ToString(); csettings.DimensionSettings.Add(dm); i++; } FlatDataConnectionSettings flatDataSettings = new FlatDataConnectionSettings(); FlatDataSource flatDataSource = new FlatDataSource { ConnectionSettings = flatDataSettings }; flatDataSource.CubesSettings.Add(csettings); flatDataSource.ItemsSource = flatData;
Maybe the problem is with this line:
new CubeMetadata { DataTypeFullName = flatData.GetType().ToString(), DisplayName = "DisplayNameXYZ" };
What exactly should be in DataTypeFullName? Maybe flatData.GetType().ToString() is not exactly what is needed.
Hello,
What is the type of flatData instance? I think that is your IEnumerable that you use as data source. As DataTypeFullName you need to pass the full type name of items stored into the IEnumerable. If your data source is an IEnumerable<T> you need to pass typeof(T).FullName:
CubeMetadata csettings = new CubeMetadata { DataTypeFullName = typeof([Your Items Type Here])ToString(), DisplayName = "DisplayNameXYZ" };
Plamen.
Dear Plamen,
Thank you very much, it works fine. It was the fullname that was not correct. Thanks for your help!
Have a nice day,