Category / Section
How to make the Numeric Sorting possible
1 min read
Pivot Grid will populate the data in ascending order by default with numeric string sorting. However, we suggest you to use the custom comparer to arrange the Pivot Row values with the numeric sorting. You can use the below code snippet to arrange Pivot Row values with the numeric sorting
C#
public MainWindow() { InitializeComponent(); this.DataContext = new ViewModel(); this.grd.PivotRows.Add(new PivotItem { FieldMappingName = "Day", TotalHeader = "Total", Comparer = new MyComparer() }); } public class MyComparer : IComparer { #region IComparer Members public int Compare(object x, object y) { if (x == null && y == null) return 0; else if (y == null) return 1; else if (x == null) return -1; else return int.Parse(x.ToString()).CompareTo(int.Parse(y.ToString())); } #endregion }