Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
655
Initialize FlatDataSource from code
posted

Hello!

I need a way to initialize FlatDataSource from code. I use MVVM pattern and currently FlatDataSource in my ViewModel is populated with initial items and initialized only after view have been initialized. Now if I want to do something with initialized datasource, I do this in ResultChanged event handler. But this breaks View-ViewModel separation and I can't properly test my code.

Maybe I'm missing something? How can I initialize FlatDataSource with items from ItemsSource without loading the PivotGrid?

Here is my code to generate FlatDataSource:

DataSource = new FlatDataSource
{
ItemsSource = Items,
Cube = DataSourceBase.GenerateInitialCube("DistributorInventory"),
Rows = DataSourceBase.GenerateInitialItems("[Distributor].[Distributor]"),
Columns = DataSourceBase.GenerateInitialItems("[Date].[Date]"),
Measures = DataSourceBase.GenerateInitialItems("Value")
};

var cubeMetadata = new CubeMetadata
{
DisplayName = "Cube",
DataTypeFullName = typeof(DistributorInventory).FullName
};
cubeMetadata.DimensionSettings.Add(new DimensionMetadata
{
SourcePropertyName = "Value",
DisplayName = "Value",
});
DataSource.CubesSettings.Add(cubeMetadata);

var datesHierarchy = new HierarchyDescriptor(p => p.Date) {HierarchyDisplayName = "Date"};
datesHierarchy.AddLevel(p => p.MonthText, "Month");
datesHierarchy.AddLevel(p => p.WeekText, "Week");
DataSource.AddHierarchyDescriptor(datesHierarchy);

var itemsHierarchy = new HierarchyDescriptor(p => p.Distributor) {HierarchyDisplayName = "Distributor"};
itemsHierarchy.AddLevel(p => p.Distributor, "Distributor");
itemsHierarchy.AddLevel(p => p.Address, "Address");
itemsHierarchy.AddLevel(p => p.Item, "Item");
DataSource.AddHierarchyDescriptor(itemsHierarchy);

DataSource.ResultChanged += OnDataSourceOnResultChanged;