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
860
Sorting in XamPivotGrid
posted

Hello

I have a couple of questions regarding XamPivotGrid and FlatDataSource. 

1. 

I have a HierarchyDescriptor with a month:

dateTimeDataDescriptor.AddLevel<DateTime>(date =>
date.ToString("MMM", CultureInfo.CurrentCulture),
"Months"
);

It will give me the months like: jan, feb, mar, etc. The problem is when I sort, which will be sorted alphabetically. This is not correct in this case as you would expect jan to be first. Is there any way to control this?

2.

How do I set the default sorting to ASC. Whenever I add a row or a column I would like it to be sorted. 

Parents
  • 17475
    Verified Answer
    Offline posted

    Hello,

    The OrderByKeyExpression property should be set to an expression in order to sort a hierarchy descriptor.


    Expression<Func> orderByExpression = d => d.Date.Month;
                datesHierarchy.LevelDescriptors[0].OrderByKeyExpression = orderByExpression;

    Since the Date.Month is actually an integer value, the type of the result is also specified as int. I have attached a sample project illustrating the approach.


    You can add LevelSortDirections to the FlatDataSource. LevelDefaultSortDirections list in order to sort the FlatDataSorce in code.


    LevelSortDirection sortDirection = new LevelSortDirection();
    sortDirection.LevelUniqueName = "[DimensionName].[HierarchyName].[ LevelName]";
    sortDirection.SortDirection = ListSortDirection.Ascending;
    dataSource.LevelDefaultSortDirections.Add(sortDirection);

    Please feel free to let me know if you need additional assistance.

    XamPivotGridFlatDataSort.zip
Reply Children