Working with Expressions
Apart from building complex filtering criteria by means of the visual UI, RadFilter also provides the option of adding filter and group expressions programmatically. Saving and loading expressions is also supported.
RadFilter FilterExpression types
The following table describes all filter expression types you can use:
FilterExpression type | Description |
---|---|
RadFilterBetweenFilterExpression | Represents Between RadFilter filter expression where T is the type of the field on which filter will be applied. |
RadFilterNotBetweenFilterExpression | Represents NotBetween RadFilter filter expression where T is the type of the field on which filter will be applied. |
RadFilterContainsFilterExpression | Represents Contains RadFilter filter expression. |
RadFilterGreaterThanFilterExpression | Represents GreaterThan RadFilter filter expression where T is the type of the field on which filter will be applied. |
RadFilterGreaterThanOrEqualToFilterExpression | Represents GreaterThan or EqualTo RadFilter filter expression where T is the type of the field on which filter will be applied. |
RadFilterGroupFilterExpression | Represents a group of filter expressions. |
RadFilterIsEmptyFilterExpression | Represents IsEmpty RadFilter filter expression. |
RadFilterNotIsEmptyFilterExpression | Represents IsEmpty RadFilter filter expression. |
RadFilterNotIsNullFilterExpression | Represents IsNotNull RadFilter filter expression. |
RadFilterIsNullFilterExpression | Represents IsNull RadFilter filter expression. |
RadFilterLessThanFilterExpression | Represents LessThan RadFilter filter expression where T is the type of the field on which filter will be applied. |
RadFilterLessThanOrEqualToFilterExpression | Represents LessThan or EqualTo RadFilter filter expression where T is the type of the field on which filter will be applied. |
RadFilterEqualToFilterExpression | Represents EqualTo RadFilter filter expression where T is the type of the field on which filter will be applied. |
RadFilterNotEqualToFilterExpression | Represents NotEqualTo RadFilter filter expression where T is the type of the field on which filter will be applied. |
RadFilterStartsWithFilterExpression | Represents StartsWith RadFilter filter expression. |
RadFilterEndsWithFilterExpression | Represents EndsWith RadFilter filter expression. |
Adding RadFilter expressions programmatically
You can create filter expressions as well as group expressions in the code behind. Please note that the group expressions should first be added to the RootGroup, and the filter expressions to be added to them.
In the following sample it is shown how to programmatically create a expression that filters the Orders table for orders with ShipName that starts with an 'A' and OrderDate either in the previous month, or not specified:
<telerik:RadFilter RenderMode="Lightweight" runat="server" ID="RadFilter1" ExpressionPreviewPosition="Bottom">
<FieldEditors>
<telerik:RadFilterTextFieldEditor FieldName="ShipName" />
<telerik:RadFilterDateFieldEditor FieldName="OrderDate" />
</FieldEditors>
</telerik:RadFilter>
<asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="Select OrderID, OrderDate, ShipVia, ShipName, ShipAddress, ShipCity, ShipCountry FROM Orders">
</asp:SqlDataSource>
This will result in the following: