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
615
Disable multi level of Datetime field
posted

Hi All,

Currently if we add Datetime field into pivotgrid it auto generate Year,Half year, quarter, month... but sometime user just want to see date only such as order date, invoice date. To see date level user must drill down until date level and take a lot of manipulation.

So, do we have any option to disable unused levels?  Do we have option to auto generate Year, Quarter, Month, Week... into seperated dimension such as pivot control of Radar-Soft.

Thanks

Han

Parents
  • 8831
    Verified Answer
    posted

    Hello Han,

    You can customize the datatime's hierarchy structure. You need to create a new hierarchy descriptor applied to DateTime types.
    Below is shown the structure of the descriptors used by defult. Just skip the levels you don't need to appear in your hierarchy.

    HierarchyDescriptor dateTimeDescriptor = new HierarchyDescriptor { AppliesToPropertiesOfType = typeof(DateTime) };

    dateTimeDescriptor.AddLevel<DateTime>(dt => "AllPeriods", "All Periods");
    dateTimeDescriptor.AddLevel<DateTime>(dt => dt.Year, "Years");
    dateTimeDescriptor.AddLevel<DateTime>(dt => dt.SemesterShort(), "Semesters");
    dateTimeDescriptor.AddLevel<DateTime>(dt => dt.QuarterShort(), "Quarters");
    dateTimeDescriptor.AddLevel<DateTime>(dt => dt.MonthShort(), "Months");

    Expression<Func<DateTime, int>> expression = pd => pd.Month;
    dateTimeDescriptor.LevelDescriptors[4].OrderByKeyExpression = expression;

    dateTimeDescriptor.AddLevel<DateTime>(dt => dt.Date.ToShortDateString(), "Dates");

    If you DateTime is nullable the applied expressions are little bit more complex:

    HierarchyDescriptor dateTimeDescriptor = new HierarchyDescriptor { AppliesToPropertiesOfType = typeof(DateTime?) };
    dateTimeDescriptor.AddLevel<DateTime?>(dt => "AllPeriods", "All Periods");
    dateTimeDescriptor.AddLevel<DateTime?>(dt => dt.HasValue ? dt.Value.Year.ToString() : "N/A", "Years");
    dateTimeDescriptor.AddLevel<DateTime?>(dt => dt.HasValue ? dt.Value.SemesterShort() : "N/A", "Semesters");
    dateTimeDescriptor.AddLevel<DateTime?>(dt => dt.HasValue ? dt.Value.QuarterShort() : "N/A", "Quarters");
    dateTimeDescriptor.AddLevel<DateTime?>(dt => dt.HasValue ? dt.Value.MonthShort() : "N/A", "Months"); 

    Expression<Func<DateTime?, int>> expression = dt => dt.HasValue ? dt.Value.Month : 13;
    dateTimeDescriptor.LevelDescriptors[4].OrderByKeyExpression = expression; 

    dateTimeDescriptor.AddLevel<DateTime?>(dt => dt.HasValue ? (object)dt.Value.Date : "N/A", "Dates");

    // Then add this descriptor to your flat data source:
    flatDataSource.AddHierarchyDescriptor(dateTimeDescriptor);

    You can find more information about hierarchy descriptors usage here

    Best regards.
    Plamen.

Reply Children
No Data