Sort Comparer
How to add a comparer to a field without adding the field to PivotRows or PivotColumns collections?
Usually, to add a comparer to a field, we do it like this:
PivotGridControl.PivotRows.Add(new PivotItem(){Comparer = itemComparer.Instance, FieldMappingName="item"});
But this approach would add the row to UI. I would not like to add it to UI. If the user selects a row from PivotSchemaDesigner, the comparer must be present. How to achieve this?
SIGN IN To post a reply.
3 Replies
DK
Dineshraj Kumar
Syncfusion Team
February 27, 2018 12:12 PM UTC
Hi Chaitanya,
We have checked your requirement – “ To add the comparer for any item without adding it into UI”. You can achieve your requirement by setting the Comparer for any item in CollectionChanged event handler method of PivotRows and PivotColumns collection when adding the items dynamically.
Please refer to the below code example.
|
#MainWindow.xaml.cs
using Syncfusion.Windows.Controls.PivotGrid;
using System.Windows;
using Syncfusion.PivotAnalysis.Base;
using System.ComponentModel;
public MainWindow()
{
InitializeComponent();
pivotGrid1.PivotRows.CollectionChanged += PivotItems_CollectionChanged;
pivotGrid1.PivotColumns.CollectionChanged += PivotItems_CollectionChanged;
}
private void PivotItems_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if(e.NewItems != null && e.NewItems[0] is PivotItem)
{
(e.NewItems[0] as PivotItem).Comparer = new ReverseOrderComparer();
if (pivotGrid1.PivotEngine != null && !DesignerProperties.GetIsInDesignMode(pivotGrid1))
{
pivotGrid1.PivotEngine.RaisePivotSchemaChangedEvent(new PivotSchemaChangedArgs());
}
}
}
|
Please find our working sample from the following location:
Regards,
Dineshraj K.
CH
chaitanya
February 28, 2018 07:55 AM UTC
The above solution works. Thanks a lot.
PR
Padmini Ramamurthy
Syncfusion Team
March 2, 2018 03:33 AM UTC
Hi Chaitanya,
Thanks for your response and please get back to us if you need any other assistance.
Regards,
Padmini R.
SIGN IN To post a reply.
- 3 Replies
- 3 Participants
-
CH chaitanya
- Feb 26, 2018 11:29 AM UTC
- Mar 2, 2018 03:33 AM UTC