In the current version, PivotGridControl doesn't support sorting by summary values, replaced in the PivotGridControl.CustomCellValue event. It's because PivotGridControl first filters, groups and sorts cell values and then raises the PivotGridControl.CustomCellValue and PivotGridControl.CustomCellDisplayText events. This example demonstrates how to implement sorting for such values. Note that this solution will work in simple cases and depends on the layout. In many cases, when it's not required to get other cell values, this approach can be replaced with handling the PivotGridControl.CustomSummary event.
Some key points include:
- In the PivotGridControl.CustomFieldSort event, custom cell values can't be obtained because they are not formed by this moment. The FormLoad event is used to remember custom field values into a special variable for further calculation in the PivotGridControl.CustomFieldSort event.
- As PivotGridControl sorts cell values by SortBySummaryInfo, to disable sorting by summary, PivotGridControl.ShowMenu event is handled to prevent fields sort menu from being shown. The PivotGridControl.MouseClick event is handled to calculate sort info when a user clicks PivotGridControl's column value.
-When you sort pivot rows or columns by summary values, the PivotGrid uses the sort order specified in row or column fields, and does not use sort settings from a data field used for sorting. PivotGridControl.CustomFieldSort event is handled for the PivotArea.RowArea field. This allows users to change the row values order by comparing remembered custom cell values in the cell area using sort info calculated on the PivotGridControl.MouseClick event.
Question Comments
Added By: D. Samsonoff at: 10/25/2013 7:56:49 AM
Quite fragile code. Several issues before this can be used by anyone:
- Difficult to make it work generically. We have a mix of Unbound (some of which rely on CustomCellValue for sourcing data) and Bound fields.
- Sorting needs to work of Menus just as for the supported fields as we have a mixture (see above). More hacking required.
- Consider changes to Row Fields. So additional event handling is required to reset caches.
- Memory footprint and performance is degraded.
Please fix your code so that values produced by CustomCellValue event are fully integrated into infrastructure and can be used with Filtering and Sorting out-of-the-box.
Added By: Martin D. at: 7/24/2014 4:23:45 PMHi,
this sample is broken. It's on .net 3.5 - so doesn't work with 14.1 dx
Upgrading it to .net 4.5 - causes issues with Table adapted.
could You plz fix it ?