Back to Devexpress

PivotGridControl.FilterPopupExcelData Event

windowsforms-devexpress-dot-xtrapivotgrid-dot-pivotgridcontrol-a30ca5e6.md

latest13.9 KB
Original Source

PivotGridControl.FilterPopupExcelData Event

Allows you to add, remove, and modify data values and customize predefined filters in the Excel style pop-up filter menus. Filter items added manually on this event must be unique and sorted.

Namespace : DevExpress.XtraPivotGrid

Assembly : DevExpress.XtraPivotGrid.v25.2.dll

NuGet Package : DevExpress.Win.PivotGrid

Declaration

csharp
[DXCategory("Behavior")]
public event FilterPopupExcelDataEventHandler FilterPopupExcelData
vb
<DXCategory("Behavior")>
Public Event FilterPopupExcelData As FilterPopupExcelDataEventHandler

Event Data

The FilterPopupExcelData event's data class is FilterPopupExcelDataEventArgs. The following properties provide information specific to this event:

PropertyDescription
DataItemsProvides access to the collection of data values by which the column being processed can be filtered, and the corresponding display texts. Inherited from ExcelFilteringDataEventArgs.
DisplayTextsProvides acces to the collection of the texts to be displayed in the filter popup for the corresponding data values by which the column being processed can be filtered. Inherited from ExcelFilteringDataEventArgs.
FieldGets a Pivot Grid field for which the event is raised.
FilterItemsProvides access to the collection of custom filter conditions by which the column being processed can be filtered. Inherited from ExcelFilteringDataEventArgs.
HtmlImagesGets or sets a collection of images to be inserted into filter item captions using HTML tags. This property is in effect when the HTML formatting feature is enabled for filter item captions. Inherited from ExcelFilteringDataEventArgs.
ImageAlignmentGets or sets the alignment of images fetched from the column’s image combo box editor to the filter menu. For internal use. Inherited from ExcelFilteringDataEventArgs.
ImagesProvides access to the collection of images fetched form the column’s image combo box editor to the filter menu. For internal use. Inherited from ExcelFilteringDataEventArgs.
IsInitializedGets whether these event arguments contain data values. Inherited from ExcelFilteringDataEventArgs.
IsNotLoadedGets or sets whether the data is not yet loaded during asynchronous data loading. Inherited from ExcelFilteringDataEventArgs.
ValuesProvides access to the collection of data values by which the column being processed can be filtered. Inherited from ExcelFilteringDataEventArgs.

The event data class exposes the following methods:

MethodDescription
AddData(Object, String, Boolean)Adds the specified data value by which the column being processed can be filtered, and the corresponding text to be displayed in the filter popup. Inherited from ExcelFilteringDataEventArgs.
AddFilter(String, CriteriaOperator, Boolean)Adds the specified filter condition by which the column being processed can be filtered, and the corresponding text to be displayed in the filter popup. Inherited from ExcelFilteringDataEventArgs.
AddFilter(String, String, Boolean)Adds the specified filter condition by which the column being processed can be filtered, and the corresponding text to be displayed in the filter popup. Inherited from ExcelFilteringDataEventArgs.
ChangeText(Object, String)Changes the display text in the filter popup for the specified data value. Inherited from ExcelFilteringDataEventArgs.
ClearData()Removes all items from the collection of data values by which the column being processed can be filtered. Inherited from ExcelFilteringDataEventArgs.
GetDisplayTexts()Returns an array of strings representing captions for filters in the popup. Inherited from ExcelFilteringDataEventArgs.
GetFilterItems()Returns the collection of custom filter conditions by which the column being processed can be filtered. Inherited from ExcelFilteringDataEventArgs.
GetValues()Returns an array of objects representing data values by which the column being processed can be filtered. Inherited from ExcelFilteringDataEventArgs.
RemoveData(Object)Removes the specified data value by which the column being processed can be filtered from the filter popup. Inherited from ExcelFilteringDataEventArgs.

Examples

The code snippet below shows how to handle the PivotGridControl.FilterPopupExcelData event to add predefined filters for a specific field (‘fieldModification’).

csharp
pivotGridControl.FilterPopupExcelData += OnFilterPopupExcelData;
// ...
void OnFilterPopupExcelData(object sender, FilterPopupExcelDataEventArgs e) {
    string prefilterColumnName = fieldModification.PrefilterColumnName;
    if(e.Field == fieldModification) {
        e.AddFilter("Fuel Economy (<color=green>High</color>)", "Contains([" + prefilterColumnName + "], '6A')", true);
        e.AddFilter("Automatic Transmission (8-speed)", "Contains([" + prefilterColumnName + "], '8A')", true);
        e.AddFilter("Manual Transmission (6-speed)", "Contains([" + prefilterColumnName + "], '6M')", true);
        e.AddFilter("Manual Transmission (7-speed)", "Contains([" + prefilterColumnName + "], '7M')", true);
        e.AddFilter("Variadic Transmission", "Contains([" + prefilterColumnName + "], 'VA')", true);
        e.AddFilter("<b>Limited Edition</b>", "Contains([" + prefilterColumnName + "], 'Limited')", true);
    }
}
vb
Private pivotGridControl.FilterPopupExcelData += AddressOf OnFilterPopupExcelData
' ...
Private Sub OnFilterPopupExcelData(ByVal sender As Object, ByVal e As FilterPopupExcelDataEventArgs)
    Dim prefilterColumnName As String = fieldModification.PrefilterColumnName
    If e.Field = fieldModification Then
        e.AddFilter("Fuel Economy (<color=green>High</color>)", "Contains([" & prefilterColumnName & "], '6A')", True)
        e.AddFilter("Automatic Transmission (8-speed)", "Contains([" & prefilterColumnName & "], '8A')", True)
        e.AddFilter("Manual Transmission (6-speed)", "Contains([" & prefilterColumnName & "], '6M')", True)
        e.AddFilter("Manual Transmission (7-speed)", "Contains([" & prefilterColumnName & "], '7M')", True)
        e.AddFilter("Variadic Transmission", "Contains([" & prefilterColumnName & "], 'VA')", True)
        e.AddFilter("<b>Limited Edition</b>", "Contains([" & prefilterColumnName & "], 'Limited')", True)
    End If
End Sub

A default column filter menu contains data values available in the column. The code below shows how to populate a filter menu with custom values.

Note

The example uses the grid control. The vertical grid, tree list, and pivot grid controls provide a similar API.

In this example, the processed column contains comma-separated values that can be treated as individual tokens. The FilterPopupExcelData event allows you to populate the menu with custom tokens instead of the available data values.

csharp
readonly static char[] separators = new char[] { ',', ' ' };

void OnFilterPopupExcelData(object sender, FilterPopupExcelDataEventArgs e) {
    // Create a collection of tokens based on data values.
    var tokens = new HashSet<string>();
    for(int i = 0; i < e.Values.Length; i++) {
        var parts = ((string)e.Values[i]).Split(separators, StringSplitOptions.RemoveEmptyEntries);
        for(int j = 0; j < parts.Length; j++)
            tokens.Add(parts[j]);
    }
    // Remove the default data values from the filter menu.
    e.ClearData();
    // Populate the menu with the created tokens.
    foreach(string t in tokens.OrderBy(x => x))
        e.AddData(t, t);
}
vb
Private ReadOnly Shared separators() As Char = { ","c, " "c }

Private Sub OnFilterPopupExcelData(ByVal sender As Object, ByVal e As FilterPopupExcelDataEventArgs)
    ' Create a collection of tokens based on data values.
    Dim tokens = New HashSet(Of String)()
    For i As Integer = 0 To e.Values.Length - 1
        Dim parts = DirectCast(e.Values(i), String).Split(separators, StringSplitOptions.RemoveEmptyEntries)
        For j As Integer = 0 To parts.Length - 1
            tokens.Add(parts(j))
        Next j
    Next i
    ' Remove the default data values from the filter menu.
    e.ClearData()
    ' Populate the menu with the created tokens.
    For Each t As String In tokens.OrderBy(Function(x) x)
        e.AddData(t, t)
    Next t
End Sub

If you have populated the menu with custom tokens, you also must handle the following events:

  • FilterPopupExcelQueryFilterCriteria — to convert the selected tokens to the corresponding filter criteria that should be applied to data (direct conversion). This conversion is processed when the user selects a token in the menu/applies the selected tokens/closes the menu.

  • FilterPopupExcelParseFilterCriteria — to convert the applied filter criteria to the corresponding tokens that should be selected in the menu (reverse conversion). This conversion is processed when the user opens the menu.

See Also

FilterPopupExcelQueryFilterCriteria

FilterPopupExcelParseFilterCriteria

Pop-up Filter

PivotGridControl Class

PivotGridControl Members

DevExpress.XtraPivotGrid Namespace