I need to know how I can define rows, columns, filters and measures like you in the xaml below through code.
I need to bind to each property and due to the fact that those are not DependencyObjects I need to listen to the propertychanged of my viewmodel and set those manually. Unfortunatly I cannot find out how to add rows, measures, filters etc. to the datasource through code.
Please let me know. This is very urgent.
<olap:XmlaDataSource x:Key="DataSource" Columns="[Date].[Calendar]" Cube="Adventure Works" Database="Adventure Works DW Standard Edition" Filters="[Sales Territory].[Sales Territory Country]{[Sales Territory].[Sales Territory Country].&[United Kingdom]}" Measures="Reseller Sales Amount" Rows="[Geography].[City]" >
Hello,
You can add columns/rows/filters/measures using this code:
pivotGrid.DataSource.DeferredLayoutUpdate = true;
IMeasure measure = pivotGrid.DataSource.Cube.Measures["Reseller Sales Amount"];
IMeasureViewModel measureViewModel = pivotGrid.DataSource.CreateMeasureViewModel(measure);
pivotGrid.DataSource.Measures.Add(measureViewModel);
IDimension dateDimension = pivotGrid.DataSource.Cube.Dimensions["[Date]"];
IHierarchy dateCalendarHierarchy = dateDimension.Hierarchies["[Date].[Calendar]"];
IFilterViewModel columnViewModel = pivotGrid.DataSource.CreateFilterViewModel(dateCalendarHierarchy);
pivotGrid.DataSource.Columns.Add(columnViewModel);
// updates grid layout
pivotGrid.DataSource.DeferredLayoutUpdate = false;
Regards.Plamen.
My cube is null. GenerateInitialCube doesn't seem to help much.
private void DatabindControls() { var fds = BuildFlatDatasource(); InventoryPivotGrid.DataSource = fds; InventoryDataSelector.DataSource = fds; } private FlatDataSource BuildFlatDatasource() { var result = new FlatDataSource(); //result.DeferredLayoutUpdate = true; result.CubesSettings.Add(BuildCubeSettings()); result.DimensionsGenerationMode = DimensionsGenerationMode.Metadata; result.ItemsSource = _viewModel.FlatInventories; var initialCube = DataSourceBase.GenerateInitialCube("FlatInventories"); result.Cube = initialCube; SetDefaultMeasure(result, "Quantity"); SetDefaultColumn(result, "Product", "Product"); SetDefaultRow(result, "Location", "Installation"); //result.DeferredLayoutUpdate = false; return result; } private static void SetDefaultMeasure(FlatDataSource result, string measureName) { var measure = result.Cube.Measures[measureName]; var measureViewModel = result.CreateMeasureViewModel(measure); result.Measures.Add(measureViewModel); } private static void SetDefaultColumn(FlatDataSource result, string dimensionName, string hierarchyName) { SetDataSourceFilter(result, dimensionName, hierarchyName, ifvm => result.Columns.Add(ifvm)); } private static void SetDefaultRow(FlatDataSource result, string dimensionName, string hierarchyName) { SetDataSourceFilter(result, dimensionName, hierarchyName, ifvm => result.Rows.Add(ifvm)); } private static void SetDataSourceFilter(FlatDataSource result, string dimensionName, string hierarchyName, Action<IFilterViewModel> filterTargetApplier) { var dimension = result.Cube.Dimensions[string.Format("[{0}]", dimensionName)]; var hierarchy = dimension.Hierarchies[string.Format("[{0}].[{1}]", dimensionName, hierarchyName)]; var filterViewModel = result.CreateFilterViewModel(hierarchy); filterTargetApplier(filterViewModel); }
private void DatabindControls() { var fds = BuildFlatDatasource(); InventoryPivotGrid.DataSource = fds; InventoryDataSelector.DataSource = fds; } private FlatDataSource BuildFlatDatasource() { var result = new FlatDataSource(); //result.DeferredLayoutUpdate = true; result.CubesSettings.Add(BuildCubeSettings()); result.DimensionsGenerationMode = DimensionsGenerationMode.Metadata; result.ItemsSource = _viewModel.FlatInventories; var initialCube = DataSourceBase.GenerateInitialCube("FlatInventories"); result.Cube = initialCube; SetDefaultMeasure(result, "Quantity"); SetDefaultColumn(result, "Product", "Product"); SetDefaultRow(result, "Location", "Installation"); //result.DeferredLayoutUpdate = false; return result; }
private static void SetDefaultMeasure(FlatDataSource result, string measureName)
{ var measure = result.Cube.Measures[measureName]; var measureViewModel = result.CreateMeasureViewModel(measure); result.Measures.Add(measureViewModel); } private static void SetDefaultColumn(FlatDataSource result, string dimensionName, string hierarchyName) { SetDataSourceFilter(result, dimensionName, hierarchyName, ifvm => result.Columns.Add(ifvm)); } private static void SetDefaultRow(FlatDataSource result, string dimensionName, string hierarchyName) { SetDataSourceFilter(result, dimensionName, hierarchyName, ifvm => result.Rows.Add(ifvm)); } private static void SetDataSourceFilter(FlatDataSource result, string dimensionName, string hierarchyName, Action<IFilterViewModel> filterTargetApplier) { var dimension = result.Cube.Dimensions[string.Format("[{0}]", dimensionName)]; var hierarchy = dimension.Hierarchies[string.Format("[{0}].[{1}]", dimensionName, hierarchyName)]; var filterViewModel = result.CreateFilterViewModel(hierarchy); filterTargetApplier(filterViewModel); }
BuildCubeSettings adds all metda data for dimensions and measures. This works fine, but the grid starts empty. I just want to set initial values. Can you help me out?
regards,Teun
Hello Teun,
I have been looking into your enquiry and setting Cube property of the FlatDataSource does not change its value and it shows null until the LoadCubesCompleted event is fired. You can register for it in order to see if the Cube property changes. If this doesn’t fire I can suggest sending me a test sample I can look into for you, otherwise you can try presetting the Rows, Columns and Measures dimensions:
Rows = XmlaDataSource.GenerateInitialItems("[Seller].[Seller]"),
Columns = XmlaDataSource.GenerateInitialItems("[Product].[Product]"),
Measures = XmlaDataSource.GenerateInitialItems("AmountOfSale")
like in the “FlatDataSource (Code behind)” sample: http://ko.infragistics.com/samples/silverlight/pivot-grid/#/flatdatasource-code-behind
Please let me know, if you need any further assistance with this.