Drill Down to the Underlying Data

  • 4 minutes to read

A pivot grid cell's value is a summary calculated against a data field for a subset of records retrieved from the PivotGrid's underlying data source.

pivotgrid_vs_grid

In the previous image, the pivot grid's highlighted cell value ($88.640.00) is calculated as a sum of Price field values for the records that meet the following criteria:

  • the Model field value is equal to the row field value (S-Type 3.0)
  • the Order Date field value is equal to the column field value (11/14/2002)

To get underlying records for a particular cell, use the CreateDrillDownDataSource method. The following table shows how to access this method in different situations:

Situation Instruction
Click or double-click the cell Handle the PivotGridControl.CellClick or PivotGridControl.CellDoubleClick event and call the e.CreateDrillDownDataSource method.
Get data for a particular cell Call the PivotGridControl.CreateDrillDownDataSource method.
Get data for a particular cell asynchronously Call the PivotGridControl.CreateDrillDownDataSourceAsync method.
Get data for a particular cell Use the GetCellInfo and GetFocusedCellInfo methods . Those methods return the PivotCellBaseEventArgs object. Call its CreateDrillDownDataSource method.
Calculate custom summary Handle the PivotGridControl.CustomSummary event and call the e.CreateDrillDownDataSource method.
Customize cell foreground and background for display and export Handle the PivotGridControl.CustomValueAppearance and call the e.CreateDrillDownDataSource method.
Display custom text Handle the PivotGridControl.FieldValueDisplayText event and call the e.CreateDrillDownDataSource method..

Example: How to Obtain Underlying Data

This example demonstrates how to obtain the records from the control's underlying data source for a particular cell. Double-click a cell to invoke a form that contains a grid with the underlying data.

NOTE

The complete sample project How to: Display Underlying (Drill-Down) Records is available in the DevExpress Examples repository.

This example is based on the DevExpress MVVM Framework. When a user double-clicks a cell, the EventToCommand class invokes the bound ShowDrillDownDataCommand defined in the ViewModel.

To pass the event data as a parameter to the command, the EventToCommand.PassEventArgsToCommand property is set to true. The EventArgsToCellInfoConverter instance is assigned to the EventToCommand.EventArgsConverter property to convert the event data to the CellInfo parameter type required for the command.

The command calls the DialogService.ShowDialog method to invoke a custom window that displays the underlying data. The DialogService is a part of the DevExpress MVVM Framework. It is defined in XAML and specifies the DXDialogWindow that contains the GridControl bound to the CellInfo.DrillDownDataSource property.

using DevExpress.Mvvm;
using DevExpress.Mvvm.DataAnnotations;
using DevExpress.Mvvm.POCO;
using DevExpress.Xpf.PivotGrid;
using HowToObtainUnderlyingData.NWindDataSetTableAdapters;
using static HowToObtainUnderlyingData.NWindDataSet;

namespace HowToObtainUnderlyingData
{
    [POCOViewModel]
    public class ViewModel {
        SalesPersonTableAdapter salesPersonDataAdapter = new SalesPersonTableAdapter();
        public SalesPersonDataTable DataSource { get; } = new SalesPersonDataTable();

        protected ViewModel() {
            salesPersonDataAdapter.Fill(DataSource);
        }

        public void ShowDrillDownData(CellInfo cellInfo) {
            this.GetService<IDialogService>().ShowDialog(MessageButton.OK, "Drill Down Results", cellInfo);
        }
    }
}
See Also