We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to default sort my pivot grid control

Thread ID:

Created:

Updated:

Platform:

Replies:

128655 Feb 3,2017 03:17 AM Feb 6,2017 05:29 AM WPF 1
loading
Tags: PivotGridControl
César
Asked On February 3, 2017 03:17 AM

I use a Pivot Grid Control with the following rows and columns.
Columns: Week, Day
Rows: Catalogue, Person, Client

I have two problems.
1.- The pivot grid control have default sort (alphabetically (with DateTime I don´t know exactly how it works)). Can I sort it how I want?
2.- By default, the pivot grid appears with all the nodes expanded. I have created a button that collapsed all of them. The problem is, when I expand one row of the first level (catalogue), all the nodes in second level (person) appears expanded. I need to only expand when I request for it.

Thank for your attention,

Cesar

Sabaridass Ramamoorthy [Syncfusion]
Replied On February 6, 2017 05:29 AM

Hi Cesar, 
 
Thank you for contacting Syncfusion support. 
 
Please find our response below. 
 
Query 
Response 
1.- The pivot grid control have default sort (alphabetically (with DateTime I don´t know exactly how it works)). Can I sort it how I want? 
We are have the support to sort the values by using your own sorting functionality for PivotGrid control. This can be achieved by using the Comparer property for PivotItem class.   
 
Please find the attached sample from the below location. 
 
Please refer to the below code example. 
# Code-Behind 
 
public partial class MainWindow : Window 
    { 
        public MainWindow() 
        { 
            InitializeComponent(); 
            pivotGrid1.PivotColumns[0].Comparer = new WeekComparer(); 
            pivotGrid1.PivotColumns[1].Comparer = new DayComparer(); 
        }       
    } 
 
    public class DayComparer : IComparer 
    { 
        /// <summary> 
        /// Compare for DateTime objects. 
        /// </summary> 
        /// <param name="x">object.</param> 
        /// <param name="y">object.</param> 
        /// <returns>integer</returns> 
        public int Compare(object x, object y) 
        { 
            DateTime dummyX, dummyY; 
            if (x == null && y == null) 
                return 0; 
            else if (y == null) 
                return 1; 
            else if (x == null) 
                return -1; 
            else if (DateTime.TryParseExact(x.ToString(), "dd", CultureInfo.InvariantCulture, DateTimeStyles.None,  out dummyX) && DateTime.TryParseExact(y.ToString(), "dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out dummyY)) 
                return DateTime.Compare(dummyX.Date, dummyY.Date); 
            else 
                return 0; 
        } 
    } 
 
    public class WeekComparer  :IComparer 
    { 
        /// <summary> 
        /// Compare for DateTime objects. 
        /// </summary> 
        /// <param name="x">object.</param> 
        /// <param name="y">object.</param> 
        /// <returns>integer</returns> 
        public int Compare(object x, object y) 
        { 
            int dt1 = (int)Enum.Parse(typeof(DayOfWeek), x.ToString()); 
            int dt2 = (int)Enum.Parse(typeof(DayOfWeek), y.ToString()); 
            if (x == null && y == null) 
                return 0; 
            else if (y == null) 
                return 1; 
            else if (x == null) 
                return -1; 
            else 
                return dt1.CompareTo(dt2); 
        }        
    } 
 
2.- By default, the pivot grid appears with all the nodes expanded. I have created a button that collapsed all of them. The problem is, when I expand one row of the first level (catalogue), all the nodes in second level (person) appears expanded. I need to only expand when I request for it. 
As per the current behavior of PivotGrid control, when collapsing all the fields using “CollapseAllGroup()” method, all the fields collapse based on the parent node. So we cannot maintain the collapsed states of the child nodes when expanding the parent node. However, we have logged an improvement task for your requirement and it will be implemented in one of our upcoming volume releases.   
 
Regards, 
Sabaridass R. 
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;