How to: Add and Remove Items From Filter Drop-Down Lists

  • 2 minutes to read

The following example shows how to add and remove items from the filter dropdown list.

In this example, the 'Beverages' item is hidden from the filter dropdown list of the Category field, and a dummy item is created and added to the list. To do this, the CustomFilterPopupItems event is handled. In the event handler, the 'Beverages' item is removed from the event parameter's Items collection, and a new item ('Dummy Item') is added to the collection.

View Example

<dx:ASPxPivotGrid ID="ASPxPivotGrid1" runat="server" DataSourceID="AccessDataSource1" 
OnCustomFilterPopupItems="ASPxPivotGrid1_CustomFilterPopupItems">
    <Fields>
        <dx:PivotGridField ID="fieldProductName" Area="RowArea" AreaIndex="1"
        Caption="Product Name" FieldName="ProductName">
        </dx:PivotGridField>
        <dx:PivotGridField ID="fieldShippedYear" Area="ColumnArea" AreaIndex="0" Caption="Year"
            FieldName="ShippedDate" GroupIndex="0" GroupInterval="DateYear" InnerGroupIndex="0">
        </dx:PivotGridField>
        <dx:PivotGridField ID="fieldProductSales" Area="DataArea" AreaIndex="0" Caption="Sales"
            FieldName="ProductSales">
        </dx:PivotGridField>
        <dx:PivotGridField ID="fieldCategoryName" Area="RowArea" AreaIndex="0"
        Caption="Category Name" FieldName="CategoryName">
        </dx:PivotGridField>
        <dx:PivotGridField ID="fieldShippedMonth" Area="ColumnArea" AreaIndex="2" Caption="Month"
            FieldName="ShippedDate" GroupIndex="0" InnerGroupIndex="2" GroupInterval="DateMonth">
        </dx:PivotGridField>
        <dx:PivotGridField ID="fieldShippedQuarter" Area="ColumnArea" AreaIndex="1"
        Caption="Quarter" FieldName="ShippedDate" GroupIndex="0"
        GroupInterval="DateQuarter" InnerGroupIndex="1"
        ValueFormat-FormatString="Quarter {0}"
        ValueFormat-FormatType="Custom">
        </dx:PivotGridField>
    </Fields>
    <Groups>
        <dx:PivotGridWebGroup />
    </Groups>
</dx:ASPxPivotGrid>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/nwind.mdb"
    SelectCommand="SELECT [CategoryName], [ProductName], [ProductSales],
    [ShippedDate] FROM [ProductReports]">
</asp:AccessDataSource>