Skip to main content

Custom Formatting

  • 3 minutes to read

The Pivot Grid allows custom text to be displayed within individual data cells. To do this, handle the ASPxPivotGrid.CustomCellDisplayText event. This event is fired for each cell in bound and unbound fields.

Each data cell displays a summary value calculated against Data Field. This data field is returned by the event parameter’s PivotCellEventArgsBase<TField, TData, TCustomTotal>.DataField property. The cell’s current value is returned by the event parameter’s PivotCellEventArgsBase<TField, TData, TCustomTotal>.Value property.

To change the cell’s display text, use the PivotCellDisplayTextEventArgs.DisplayText property. Initially, this property contains the text currently displayed within a cell. To provide a custom text, assign it to the PivotCellDisplayTextEventArgs.DisplayText property.

Example: How to Format Cells via Events

The following example shows how to provide custom text for the ASPxPivotGrid’s cells by handling the ASPxPivotGrid.CustomCellDisplayText event.

In this example, if a Grand Total value is less than 50 000, ASPxPivotGrid displays the Low value instead. If the value exceeds 100 000, High is displayed; otherwise, Middle.

using System;
using System.Web.UI;
using DevExpress.Web.ASPxPivotGrid;
using DevExpress.XtraPivotGrid;

namespace FormattingViaEvents {
    public partial class _Default : Page {
        protected void Page_Load(object sender, EventArgs e) {
        }
        protected void CustomCellDisplayText(object sender, PivotCellDisplayTextEventArgs e) {
            if (e.RowValueType != PivotGridValueType.GrandTotal ||
                e.ColumnValueType == PivotGridValueType.GrandTotal) return;
            if (Convert.ToSingle(e.Value) < 50000)
                e.DisplayText = "Low";
            else if (Convert.ToSingle(e.Value) > 100000)
                e.DisplayText = "High";
            else
                e.DisplayText = "Middle";
        }
    }
}