Skip to main content

How to Apply a Filter to a Field

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.

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;

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