DataFilter supports conditional filtering operations which can be used to apply filters based on specific conditions. It enables you to highlight critical information, and identify the records that fit a specific condition, when working with a large dataset. With the help of this feature, you can apply conditional filtering on different data types like text, numeric, and date.
In DataFilter, ConditionalFilter class represents conditional filters. In addition, some more conditional filters are also available in DataFilter that you can use to implement conditional filtering based on the data type of columns. The description of these conditional filters is as follows:
These classes provide various properties to customize conditional filtering operations for specified data column.
You can set the initial filter operation for various conditional filters such as NumericFilter, DateTimeFilter, TextFilter, etc., by using the DefaultFilterOperation property of the ConditionalFilter class. For example, in case of TextFilter, the default value of the DefaultFilterOperation property is set to Contains. By overriding the default value and setting it to FilterOperation.StartsWith using the DefaultFilterOperation property, users can customize how the filter evaluates text data. This allows for more specific filtering criteria, enabling applications to focus on particular needs, like identifying strings that start with a given prefix. You can set the default value of the DefaultFilterOperation property for both manually created and autogenerated filters.
In case of autogenerated Text filter, you can easily override the default TextFilter condition Contains with StartsWith condition filter by using the following code. This example uses the same data and code which is used in Types of Filter.
However, in case of manually created TextFilter, you can override the default filter condition Contains with StartsWith condition by using the following code:
C# |
Copy Code
|
---|---|
foreach (var filter in c1DataFilter.Filters) { if (filter is TextFilter textFilter) { textFilter.DefaultFilterOperation = FilterOperation.StartsWith; } } |