ReoGrid
DOCUMENT
Conditional Filters

Conditional Filters

Use ConditionalDataFilter to hide rows whose values do not satisfy a set of column rules. Filters work against a ColumnBasedDataSource attached to a worksheet range and can be combined with other row filters (for example, free‑text search).

Prerequisites

  • Attach a ColumnBasedDataSource that names each column you want to filter:
    sheet.AddDataSource(range, dataSource);
    Worksheet.DoFilter will throw if the range has no data source or if the data source is not column‑based.
  • Column IDs in FilterCondition.ColumnID must exist in ColumnBasedDataSource.Columns; otherwise a ColumnDefineNotFoundException is raised during BeginFilter.
  • Filtering hides rows by setting their height to 0. Any filter combination must call Worksheet.DoFilter(range, filter);.

Create and manage rules

ConditionalDataFilter.Conditions holds the active rules. Add or clear items and toggle FilterCondition.IsEnabled to control what runs.

using unvell.ReoGrid;
using unvell.ReoGrid.Data;
using unvell.ReoGrid.Data.ConditionFilter;

var sheet = grid.CurrentWorksheet;
var (ds, range) = BuildColumnDataSource();     // returns ColumnBasedDataSource + its range
sheet.AddDataSource(range, ds);

var filter = new ConditionalDataFilter
{
    ErrorOnMismatchedType = false,             // throw on numeric/type mismatch if true
};

filter.Conditions.AddRange(
    new FilterCondition("price", ConditionOperator.GreaterThan, 1000),
    new FilterCondition("currency", ConditionOperator.Equals, "USD", CellDataKind.Value, ComparisonType.Text),
    new FilterCondition("tradeDate", ConditionOperator.Equals, "2024-05") // month‑level match
);

filter.OnApply += (s, e) => sheet.DoFilter(range, filter);
filter.Apply();                                // evaluates rules and hides rows

Key rule settings

  • Operators (ConditionOperator): Equals, NotEquals, StartsWith, EndsWith, Contains, NotContains, GreaterThan, EqualsOrGreaterThan, LessThan, EqualsOrLessThan, Includes (array membership).
  • Column: ColumnID must match a data source column name; ColumnIndex is assigned automatically during BeginFilter.
  • Value parsing (ComparisonType): default Auto tries numeric → datetime → text.
    • Numeric parsing accepts numbers, strings, StringBuilder, and percentages such as "100%" (0.0–1.0 range).
    • Datetime parsing accepts DateTime values and many string forms (yyyy/MM/dd, yyyyMMdd, yyyy-M, yyyy年M月d日, h:m[:s], and general DateTime.TryParse).
    • Equality on dates respects DateTimeValidPart inferred from the format (e.g., YYYY, YYYYMM, YYYYMMDD, HHMM, HHMMSS).
  • Comparison target (ComparisonDataKind): use CellDataKind.Value (default) to compare raw values or CellDataKind.DisplayText to compare formatted text. The sample UI switches date columns to DisplayText when matching the rendered string.
  • Array rules: ConditionOperator.Includes accepts any IEnumerable; set ComparisonType.Numeric to require numeric members.
  • Null/empty handling: empty strings and null are treated as equal during equality checks.

Apply filters alone or in combination

Call Worksheet.DoFilter(range, filter) when rules change. A typical pattern is to run it from the filter’s OnApply event so UI changes trigger a re‑apply. To combine with other filters (for example, TextSearchDataFilter), wrap them in MultipleDataFilter:

var condition = new ConditionalDataFilter();
var search = new TextSearchDataFilter();
var filters = new MultipleDataFilter();
filters.Filters.Add(condition);
filters.Filters.Add(search);

condition.OnApply += (s, e) => sheet.DoFilter(range, filters);
search.OnApply += (s, e) => sheet.DoFilter(range, filters);

When you change conditions (add/remove, update values, toggle IsEnabled), call Apply() to raise OnApply and rerun DoFilter.


Was the content of the page helpful?

© 2012-2025UNVELL Inc.