Data Filtering
ReoGrid hides rows by running a filter over a data range. You can use the built‑in column filter UI, rule‑based conditional filters, or your own filter logic wired to any GUI you like.
Filter entry points
- Auto filter UI – Excel‑style drop‑downs that collect unique values per column. See Built‑in Auto Filter.
- Conditional filters – Rule objects (
ConditionalDataFilter + FilterCondition) evaluated against a ColumnBasedDataSource. See Conditional Filters.
- Custom filters – Implement
RowBasedDataFilter<IRowDataRecord> (or use Func<int, bool>) and call Worksheet.DoFilter(range, filter) yourself.
Minimal examples
Using a predicate
var sheet = grid.CurrentWorksheet;
var range = sheet.UsedRange;
sheet.DoFilter(range, rowIndex =>
{
var value = sheet[rowIndex, 2]; // third column
return value is double d && d >= 1000; // keep rows with value >= 1000
});
Using a data filter
var condition = new ConditionalDataFilter();
condition.Conditions.Add(new FilterCondition("price", ConditionOperator.GreaterThan, 1000));
condition.OnApply += (s, e) => sheet.DoFilter("A1:D200", condition);
condition.Apply(); // triggers DoFilter
Combining filters
Use MultipleDataFilter when you want several filters to be true at once (for example, conditional rules plus free‑text search):
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("A1:F300", filters);
search.OnApply += (s, e) => sheet.DoFilter("A1:F300", filters);
On-screen vs. data-driven filtering
- On-screen filter (UI-driven): The built-in auto filter and conditional filters hide rows that already exist on the sheet. They work against the range currently loaded in the worksheet.
- Data-driven filter: If your data source supports filtering/querying, filter there first (e.g., database query, in-memory LINQ) and then bind the filtered
ColumnBasedDataSource to the sheet. ReoGrid will display only the filtered records, and any additional on-screen filters apply on top of that.
Build your own filter UI
- Render controls (panel, list, checkboxes, etc.) wherever you want—often in a header drop‑down.
- When the user changes selections, update your filter object(s) and call
Apply(); handle OnApply to call Worksheet.DoFilter(range, filter).
- For header drop‑downs, derive from
DropdownHeaderCell and attach your control as the drop‑down content, then install the header body on the column header.
Worksheet Filter Methods
CreateColumnFilter Overloads
| Signature | Description |
|---|
CreateColumnFilter() | Auto-detect used range and create filter |
CreateColumnFilter(RangePosition range, AutoColumnFilterUI ui) | Create filter on a range |
CreateColumnFilter(string startCol, string endCol, int titleRows, AutoColumnFilterUI ui) | Create by column codes |
CreateColumnFilter(int column, int titleRows, AutoColumnFilterUI ui) | Create on a single column |
CreateColumnFilter(int startCol, int endCol, int titleRows, AutoColumnFilterUI ui) | Create by column indices |
DoFilter Overloads
| Signature | Description |
|---|
DoFilter(RangePosition range, Func<int, bool> filter) | Filter using a predicate (row index → keep?) |
DoFilter(string addressOrRange, RowBasedDataFilter<IRowDataRecord> filter) | Filter using a data filter by address |
DoFilter(RangePosition range, RowBasedDataFilter<IRowDataRecord> filter) | Filter using a data filter by range |
SortColumn
| Signature | Description |
|---|
SortColumn(string columnCode, SortOrder order) | Sort by column address code |
SortColumn(int columnIndex, RangePosition applyRange, SortOrder order) | Sort within a specific range |
SortOrder Enum
| Value | Description |
|---|
Ascending | Sort A→Z / smallest first |
Descending | Sort Z→A / largest first |
Events
| Event | Description |
|---|
RowsFiltered | Raised after rows are filtered on the worksheet |
sheet.RowsFiltered += (s, e) =>
{
Console.WriteLine("Rows have been filtered");
};
Filter Classes
RowBasedDataFilter<T> (Abstract Base)
| Member | Type | Description |
|---|
InputSource | IDataSource<T> | The data source being filtered |
IsDisabled | bool | Enable or disable the filter |
Apply() | void | Apply the filter (raises OnApply) |
OnApply | event | Raised when the filter is applied |
BeginFilter(Worksheet, ColumnBasedDataSource) | abstract | Called before filtering starts |
FilterRecord(T record) | abstract bool | Return true to keep the row |
EndFilter() | abstract | Called after filtering ends |
TextSearchDataFilter
Filters rows that contain a search string (case-insensitive, searches all columns).
| Property | Type | Description |
|---|
Text | string | The text to search for |
var search = new TextSearchDataFilter();
search.Text = "hello";
search.OnApply += (s, e) => sheet.DoFilter(range, search);
search.Apply();
MultipleDataFilter
Combines multiple filters — a row must pass all sub-filters to be visible.
| Property | Type | Description |
|---|
Filters | List<RowBasedDataFilter<IRowDataRecord>> | The list of sub-filters |
More details