Back to Devexpress

How to Apply a Filter to a Field

vcl-157001-expresspivotgrid-concepts-how-to-apply-a-filter-to-a-field.md

latest1.3 KB
Original Source

How to Apply a Filter to a Field

  • Sep 06, 2024

The following code snippet demonstrates how to filter the PivotGridPurchaseDate field which contains date-time values, by two dates: 2/1/2002 and 2/2/2002.

delphi
PivotGrid.BeginUpdate;
  with PivotGridPurchaseDate.Filter do
  begin
    with Values do
    begin
      // Clears the field's filter condition.
      Clear;
      // Adds two dates into the filter condition.
      Add(EncodeDate(2002, 2, 1));
      Add(EncodeDate(2002, 2, 2));
    end;
    // Specifies the filter type as inclusive.
    FilterType := ftIncluded;
  end;
  PivotGrid.EndUpdate;
cpp
PivotGrid->BeginUpdate();
  try {
    TcxPivotGridFieldFilter *AFilter = PivotGridPurchaseDate->Filter;
    // Clears the field's filter condition.
    AFilter->Values->Clear();
    // Adds two dates into the filter condition.
    AFilter->Values->Add(EncodeDate(2002, 2, 1));
    AFilter->Values->Add(EncodeDate(2002, 2, 2));
    // Specifies the filter type as inclusive.
    AFilter->FilterType = ftIncluded;
  }
  __finally {
    PivotGrid->EndUpdate();
  }

As a result, the pivot grid displays only the records that correspond to the created filter.