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. Image for the cookie policy date
close icon

How to default sort my pivot grid control

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

1 Reply

SR Sabaridass Ramamoorthy Syncfusion Team February 6, 2017 10:29 AM UTC

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. 
 


Loader.
Live Chat Icon For mobile
Up arrow icon