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
205
How to format column/row header?
posted

Hi,

What is the right way to format header cells? 

For example, if we look at sales data in a pivot grid and add the "Region" attribute in the "Rows" in the data selector.  We want to show in the row header "North East" when Region="NE", "South" when Region="S", etc.  I am using a flat data source.

Thanks in advance.

Houbin

Parents
  • 205
    posted

    I am actually using WPF instead of SilverLight.  I tried to repost to the WPF forum, but was denied as a duplicate post.

    Hopefully the solution will be same for WPF and SilverLight...

Reply
  • 8831
    Verified Answer
    posted in reply to Houbin
    Hello,
    You may have noticed that by default for each property of your data class we create a simple hierarchy with just one level within. It may looks like this:
    Applying hierarchy descriptors allows you to group the data in hierarchical structure. Here I suppose we have a properties with names Region and City and we have set LevelExpressionPath to target these properties
    <olap:HierarchyDescriptor SourcePropertyName="Region">
        <olap:HierarchyDescriptor.LevelDescriptors>
            <olap:HierarchyLevelDescriptor LevelName="All regions"/>
            <olap:HierarchyLevelDescriptor LevelName="Region" LevelExpressionPath="Region"/>
            <olap:HierarchyLevelDescriptor LevelName="City" LevelExpressionPath="City"/>
        </olap:HierarchyDescriptor.LevelDescriptors>
    </olap:HierarchyDescriptor>
    And here is how it may will look like:
      
    It seems that in your case the Region property contains just a short names or codes so you have to set up the level descriptors from code behind and for the level you have to use expression which point to extension method like follows:
    HierarchyDescriptor<SalesData> regionDescriptor =
        new HierarchyDescriptor<SalesData>(pd => pd.Region);
               
    // adds a root level (optional)
    regionDescriptor.AddLevel("All regions", "AllRegionsLevelName");
    regionDescriptor.AddLevel(pd => pd.GetRegionName(), "RegionsLevel");
     
    flatDataSource.HierarchyDescriptors.Add(regionDescriptor);
     
    Extension method definition:
    public static class SalesDataExtensions
    {
        public static string GetRegionName(this SalesData instance)
        {
            switch (instance.Region)
            {
                case "NE":
                    return "Nord East";
                case "S":
                    return "South";
                // add the mappings for the other regions              
            }
     
            // if mapping not found
            return instance.Region;
        }
    }

     

    If you have an access to the class definition you can use a class method instead the extension method.
    Regards.
    Plamen.
Children
No Data