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:
- DateFilter: The DataFilter control generates a DateFilter for the date data type. It basically filters data on the basis of dates.
- DateOnlyFilter: The DataFilter control generates a DateOnlyFilter which is used to filter data based on date criteria, ignoring the time component. This is particularly useful in applications where only the date is relevant, and you want to exclude the time portion to avoid discrepancies or mismatches.
- DateTimeFilter: The DataFilter control generates a DateTimeFilter to filter data based on specific date and time criteria. This can be particularly useful in applications where both the date and the precise time are relevant.
- DateTimeOffsetFilter: The DataFilter control generates a DateTimeOffsetFilter to filter data based on a date and time that includes an offset from UTC (Coordinated Universal Time), which is particularly useful in contexts where data spans multiple time zones. This ensures accurate filtering and comparisons by accounting for time zone differences.
- NumericFilter: The DataFilter control generates a NumericFilter for numeric data type. The numeric filter helps in selecting or manipulating data based on numerical criteria. For example, in a web application, users can filter products based on price ranges or filter search results based on numerical ratings.
- TextFilter: The DataFilter control generates a TextFilter for text data type. The TextFilter is mainly used for filtering or processing textual data. For example, the TextFilter can be used for filtering documents or web pages based on keywords or phrases entered by users in search queries.
- TimeOnlyFilter: The DataFilter control generates a TimeOnlyFilter to filter data based on time criteria, ignoring the date component. This can be particularly useful in scenarios where only the time of day is relevant, such as scheduling applications, daily reports, or any situation where the date is not a factor.
- TimeSpanFilter: The DataFilter control generates a TimeSpanFilter to filter data based on a range of times within a day, ignoring the date component. This is particularly useful for applications that need to analyze data based on specific times of the day, such as work schedules, activity logs, and time-specific reports.
These classes provide various properties to customize conditional filtering operations for specified data column.
Set the Initial Filter Operation
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.
<c1:C1DataFilter x:Name="c1DataFilter" AutoGenerateFilters="False">
<c1:C1DataFilter.Filters>
<c1:TextFilter PropertyName="Model" DefaultFilterOperation="StartsWith" />
<c1:NumericFilter PropertyName="MPG_City" Increment="1" />
<c1:FullTextFilter PropertyName="Brand" HeaderText="Brand" />
<c1:RangeFilter x:Name="rangeFilter" PropertyName="Price" Maximum="370485" Minimum="12565" Increment="1000" HeaderText="Price"/>
</c1:C1DataFilter.Filters>
</c1:C1DataFilter>
var dataFilter = new C1DataFilter {AutoGenerateFilters = false};
dataFilter.Filters.Add(new TextFilter {DefaultFilterOperation=FilterOperation.StartsWith,PropertyName = "Brand" });
LayoutRoot.Children.Add(dataFilter);
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;
}
}
|