aspnet-11056-components-pivot-grid-examples-data-shaping-how-to-implement-the-group-filter.md
This example demonstrates how to apply custom group filters to ASPxPivotGrid data.
In this example, a filter type is defined by setting the PivotGroupFilterValues.FilterType property to PivotFilterType.Included. To create and add group filter values to the PivotGroupFilterValues.Values and PivotGroupFilterValue.ChildValues collections the PivotGroupFilterValuesCollection.Add method is used.
using System;
using DevExpress.XtraPivotGrid;
namespace GroupFilter {
public partial class _Default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack && !IsCallback) {
// Creates a group and adds two fields to it.
PivotGridGroup OrderDateGroup = ASPxPivotGrid1.Groups.Add(fieldOrderDateYear,
fieldOrderDateMonth);
// Locks the PivotGroupFilterValues object by disabling visual updates.
OrderDateGroup.FilterValues.BeginUpdate();
// Sets a filter type.
// It specifies that the PivotGridControl should display only filter values.
OrderDateGroup.FilterValues.FilterType = PivotFilterType.Included;
// Creates a filter value and adds it to the PivotGroupFilterValues.Values collection.
OrderDateGroup.FilterValues.Values.Add(1994);
// Creates a filter value and adds it to the PivotGroupFilterValues.Values collection.
// Then creates a child value of the filter value and adds it to the parent value
// collection.
OrderDateGroup.FilterValues.Values.Add(1995).ChildValues.Add(1);
// Unlocks the PivotGroupFilterValues object.
OrderDateGroup.FilterValues.EndUpdate();
}
}
}
}
Imports Microsoft.VisualBasic
Imports System
Imports DevExpress.XtraPivotGrid
Namespace GroupFilter
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If (Not IsPostBack) AndAlso (Not IsCallback) Then
' Creates a group and adds two fields to it.
Dim OrderDateGroup As PivotGridGroup = ASPxPivotGrid1.Groups.Add(fieldOrderDateYear, fieldOrderDateMonth)
' Locks the PivotGroupFilterValues object by disabling visual updates.
OrderDateGroup.FilterValues.BeginUpdate()
' Sets a filter type.
' It specifies that the PivotGridControl should display only filter values.
OrderDateGroup.FilterValues.FilterType = PivotFilterType.Included
' Creates a filter value and adds it to the PivotGroupFilterValues.Values collection.
OrderDateGroup.FilterValues.Values.Add(1994)
' Creates a filter value and adds it to the PivotGroupFilterValues.Values collection.
' Then creates a child value of the filter value and adds it to the parent value
' collection.
OrderDateGroup.FilterValues.Values.Add(1995).ChildValues.Add(1)
' Unlocks the PivotGroupFilterValues object.
OrderDateGroup.FilterValues.EndUpdate()
End If
End Sub
End Class
End Namespace