Standard Formatting
- 2 minutes to read
PivotGridControl allows you to format the display text of its summary cells, field values, totals and grand totals before they are displayed. You can apply the standard formatting mechanism described in the Standard Numeric Format Strings, Custom Numeric Format Strings, Standard Date and Time Format Strings and Custom Date and Time Format Strings MSDN topics, or implement a custom formatting rule.
#Formatting Summary Cells
To format summary cells, use the data field's PivotGridField.CellFormat property.
<dxpg:PivotGridField Name="fieldPrice" Area="DataArea" FieldName="Price"
CellFormat="c2"/>
#Formatting Field Values
To format field values, use the field's PivotGridField.ValueFormat property.
<dxpg:PivotGridField Name="fieldOrderDate" Area="ColumnArea" FieldName="OrderDate"
ValueFormat="D"/>
#Formatting Totals and Grand Totals
To format total and grand total cells, use the PivotGridField.TotalCellFormat and PivotGridField.GrandTotalCellFormat properties, respectively. The format of total headers is specified by the PivotGridField.TotalValueFormat property. You can also provide formatting settings for individual custom totals. Use the PivotGridCustomTotal.CellFormat and PivotGridCustomTotal.Format properties to format custom total cells and headers, respectively.
<dxpg:PivotGridField Name="fieldPrice" Area="DataArea" FieldName="Price"
GrandTotalCellFormat="Total: {0:c2}"/>
#Example: How to Format Cell Values
This example demonstrates how to format values in pivot grid cells.
The PivotGridField.CellFormat property is used to format data in a custom manner. By default, cell values that correspond to currency fields are formatted as currency amounts (the formatting settings are determined by the regional settings). For the "English (United States)" culture, two digits are displayed to the right of the decimal point. In this example, the PivotGridField.CellFormat property is used to format cell values for the Freight field in a different manner. Data in these cells is formatted as integer currency values (without fractional portions).
Grand Total values are enclosed with round brackets in this sample. This setting is specified by the PivotGridField.GrandTotalCellFormat property.