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 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.
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,
I am just checking the progress of this issue and was wondering if you managed to achieve your goal or if you need any further assistance on the matter.
If the above suggestion helped you solve your issue please verify the thread as answered so other users may take better advantage of it.
Hi
For rows you should use datasource's rows collection like snippet below:
pivotGrid.DataSource.Rows.Add(rowViewModel);
Todor
Great but how could that work for rows as well?
I really appreciate your answer! Thanks so much