Like your newly released version of the xamgrid I would love to be able to use string indexers for measures within the xampivotgrid (which is great BTW and was desperately needed).
Is there anyway to manually add measures for the flatdatasource that would allow the pivotgrid to display data from a collection of data on a data class?
Thanks in advance for any tips.
Doug
That works. Ok thanks very much Plamen...
Hi Doug,
Adding it as property of ItemBuy
public string Color
{
get
return this.Product.Colour;
}
is enough for creation of another dimension.
I hope it helps.
Regards.
Hi Plamen,
You are right it did throw an exception. I had it commented out in my code for that reason.
I think I want to add it as another property of ItemBuy as another dimension. Would you mind showing me how to do that? I cant seem to get it working.
I dont really want the colours nested under the categories, just at the same level as categories are shown.
Thanks in advance,
Doug Rees
Polo Ralph Lauren
Hello,
Your last hierarchy descriptor is not applied because the lambda that you’re applying is for property that doesn’t belong to ItemBuy type.
I mean p => p.Product.Colour
Also are you sure that this line of code does not throw exception, because there is verification for declaring type of property to matches the type of generic parameter.
You may expose the color of Product as another property of ItemBuy and use it as additional dimension.
If it’s more appropriate for your needs you can add it as additional level of any of your hierarchies. The disadvantage is that you’ll see the color values after the upper level is expanded. For example:
HierarchyDescriptor<BuySheetPrototype1.PivotData.ItemBuy> categoryHierarchy = new HierarchyDescriptor<BuySheetPrototype1.PivotData.ItemBuy>(p => p.Product);categoryHierarchy.AddLevel(p => "All Categories", "All Categories");categoryHierarchy.AddLevel(p => p.Product.Category, "Category");categoryHierarchy.AddLevel(p => p.Product.Color, "Colors");flatDataSource.AddHierarchyDescriptor(categoryHierarchy);
will produce additional level filled with all of colors found for given category.
Plamen.
Hi Todor,
So I seem to have it working to a basic level using the following code. But what I need to be able to do is add other values under the Product list such as colours, departments etc, not just categories. Do I need to add them as dimensionsettings or as hierarchies?
I have to say the help files and samples are not really detailed enough for this powerful control. Do you have plans to create more detailed help on this control?
Thanks,Doug
var pivotData = BuySheetPrototype1.PivotData.PivotDataGenerator.GenerateBuys(source);
FlatDataSource flatDataSource = new FlatDataSource(){ ItemsSource = pivotData, Cube = DataSourceBase.GenerateInitialCube("ItemBuy"), Rows = DataSourceBase.GenerateInitialItems("[Product]"), Columns = DataSourceBase.GenerateInitialItems("[Store]"), Measures = DataSourceBase.GenerateInitialItems("NumberOfUnits")};
CubeMetadata cubeMetadata = new CubeMetadata();cubeMetadata.DisplayName = "Buy Data";cubeMetadata.DataTypeFullName = typeof(BuySheetPrototype1.PivotData.ItemBuy).FullName; cubeMetadata.DimensionSettings.Add(new DimensionMetadata(){ SourcePropertyName = "NumberOfUnits", DisplayName = "Number of Units", DisplayFormat = "{0:N0}"});
cubeMetadata.DimensionSettings.Add(new DimensionMetadata(){ SourcePropertyName = "RetailAmount", DisplayName = "Retail Amount", DisplayFormat = "{0:N0}"});cubeMetadata.DimensionSettings.Add(new DimensionMetadata(){ SourcePropertyName = "Product", DisplayName = "Product", AutoGenerateField=true}); cubeMetadata.DimensionSettings.Add(new DimensionMetadata(){ SourcePropertyName = "Store", DisplayName = "Store"}); flatDataSource.CubesSettings.Add(cubeMetadata);
HierarchyDescriptor<BuySheetPrototype1.PivotData.ItemBuy> sellerHierarchy = new HierarchyDescriptor<BuySheetPrototype1.PivotData.ItemBuy>(p => p.Store);sellerHierarchy.AddLevel(p => "All Stores", "All Stores");sellerHierarchy.AddLevel(p => p.Store.StoreName, "Store Name");flatDataSource.AddHierarchyDescriptor(sellerHierarchy);
HierarchyDescriptor<BuySheetPrototype1.PivotData.ItemBuy> categoryHierarchy = new HierarchyDescriptor<BuySheetPrototype1.PivotData.ItemBuy>(p => p.Product);categoryHierarchy.AddLevel(p => "All Categories", "All Categories");categoryHierarchy.AddLevel(p => p.Product.Category, "Category");flatDataSource.AddHierarchyDescriptor(categoryHierarchy);
HierarchyDescriptor<BuySheetPrototype1.PivotData.ItemBuy> colourHierarchy = new HierarchyDescriptor<BuySheetPrototype1.PivotData.ItemBuy>(p => p.Product.Colour);colourHierarchy.AddLevel(p => "All Colours", "All Colours");colourHierarchy.AddLevel(p => p.Product.Colour, "Colour");flatDataSource.AddHierarchyDescriptor(colourHierarchy);
this.pivotGrid.DataSource = flatDataSource;this.dataSelector.DataSource = flatDataSource;
public class ItemBuy{ public ItemBuy() { Product = new Product(); Store = new Store(); }
public Product Product { get; set; } public Store Store { get; set; }
public int NumberOfUnits { get; set; }
public decimal RetailAmount { get { return Product.Retail_Price * NumberOfUnits; } set { Product.Retail_Price = value / NumberOfUnits; } }}
public class Product{ public string Category { get; set; } public string Style_Description { get; set; } public string Colour { get; set; } public string Department { get; set; } public string Division { get; set; } public decimal Retail_Price { get; set; }}
public class Store{ public string StoreName { get; set; }}