The ASPxPivotGrid.CustomGroupInterval event enables you to group axis values using your own criteria. Use the GroupValue property to specify group values.
This example shows how to provide a custom criteria used to group axis values. The Custom Group Intervals feature is used to group product names and make the report more readable. The Product axis will show three intervals ("A-J", "K-S" and "T-Z").
The 'Products' field's DevExpress.XtraPivotGrid.PivotGridFieldBase.GroupInterval property is set to Custom at design-time. The grouping logic is implemented within the ASPxPivotGrid.CustomGroupInterval event handler.
The image below shows the result:
C# |
protected void ASPxPivotGrid1_CustomGroupInterval(object sender,
DevExpress.Web.ASPxPivotGrid.PivotCustomGroupIntervalEventArgs e)
{
if (e.Field.Caption != "Products") return;
if (Convert.ToChar(e.Value.ToString()[0]) < 'K')
{
e.GroupValue = "A-J";
return;
}
if (Convert.ToChar(e.Value.ToString()[0]) > 'J' && Convert.ToChar(e.Value.ToString()[0]) < 'T')
{
e.GroupValue = "K-S";
return;
}
if (Convert.ToChar(e.Value.ToString()[0]) > 'S')
e.GroupValue = "T-Z";
}
|
Aspx |
<dx:ASPxPivotGrid ID="ASPxPivotGrid1" runat="server" ClientIDMode="AutoID"
DataSourceID="SqlDataSource1" EnableTheming="True"
OnCustomGroupInterval="ASPxPivotGrid1_CustomGroupInterval" Theme="Metropolis">
<Fields>
<dx:PivotGridField Area="RowArea" AreaIndex="1" FieldName="ProductName"
Caption="Product Name">
</dx:PivotGridField>
<dx:PivotGridField Area="RowArea" AreaIndex="0" FieldName="ProductName"
ID="fieldProductName" Caption="Products" GroupInterval="Custom"
UnboundFieldName="fieldProductName">
</dx:PivotGridField>
<dx:PivotGridField Area="DataArea" AreaIndex="0" FieldName="Extended Price">
</dx:PivotGridField>
<dx:PivotGridField Area="ColumnArea" AreaIndex="0" FieldName="Sales Person">
</dx:PivotGridField>
</Fields>
</dx:ASPxPivotGrid>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:nwindConnectionString %>"
ProviderName="<%$ ConnectionStrings:nwindConnectionString.ProviderName %>"
SelectCommand="SELECT * FROM [SalesPerson]">
</asp:SqlDataSource>
|