Hu,
Is is possible to change the default date hierarchy from what it is right now: Year->Half->Quarter->Month->Day.
I would like to have a hierarchy of year->month.
Love this control btw. By far the best pivot grid out there!
Thanks,
Alex Schievink
Hello Alex,
You can override the default hierarchy descriptor used for DataTime properties with your one. You have to define one new hierarchy descriptor that applies to all of the properties with type of DataTime or if you need you can define new one only for the single property:
HierarchyDescriptor<ProductData> dateTimeTodayDescriptor =
new HierarchyDescriptor<ProductData>(pd => pd.Today);
dateTimeTodayDescriptor.AddLevel(pd => "Today", "All Dates");
dateTimeTodayDescriptor.AddLevel(pd => pd.Today.SemesterWithYear(), "Semesters");
dateTimeTodayDescriptor.AddLevel(pd => pd.Today.MonthShort(), "Months");
Here I assume that the flat data source contains items with type of ProductData and ProductData exposes property named Today.
HierarchyDescriptor dateTimeDataDescriptor =
new HierarchyDescriptor { AppliesToPropertiesOfType = typeof(DateTime) };
dateTimeDataDescriptor.AddLevel<DateTime>(dataTime => "All Dates", "All Dates");
dateTimeDataDescriptor.AddLevel<DateTime>(date => date.Year, "Years");
dateTimeDataDescriptor.AddLevel<DateTime>(date => date.SemesterWithYear(), "Semesters");
dateTimeDataDescriptor.AddLevel<DateTime>(date => date.MonthShort(), "Months");
dateTimeDataDescriptor.AddLevel<DateTime>(dataTime => dataTime.ToShortDateString(), "Dates");
flatDataSource.AddHierarchyDescriptor(dateTimeTodayDescriptor);flatDataSource.AddHierarchyDescriptor(dateTimeDataDescriptor);
flatDataSource.ItemsSource = yourItemsCollection;
The first (the generic) descriptor will be used for the dimension/hierarchy built over ProductData.Today property only. When dimensions are built over all other properties with type of DataTime will be used the second one.
Just remove the unnecessary levels. Note that here you can call extension or instance methods inside the lambda and the result will form the value used when data is visualized.
public static class Extenssions
{
public static string SemesterWithYear(this DateTime dateTime)
return dateTime.SemesterShort() + " " + dateTime.Year;
}
There are a few DateTime extension methods like SemesterShort(this DataTime) already defined inside Infragistics.Olap.FlatData namespace.
Also you have to add the descriptors before items source is set.
Best regards.
Plamen.
I would appreciate it if you can show how to do this in XAML, because I can't seem to get this to work on mine.
Hello,
You can see how to define hierarchy descriptors in XAML here:
http://help.infragistics.com/Help/NetAdvantage/WPF/2013.1/CLR4.0/html/xamPivotGrid_US_Defining_Hierarchies_And_Providing_Metadata_With_FlatData.html
Hope this helps you.