RadListView for ASP.NET AJAX features integrated filtering capabilities. Filtering
is achieved through the definition of filter expressions which should consequently
be added to the FilterExpressions collection of the control.
Each filter function has a corresponding type that should be used for the construction
of the filter expression. If, for example, a filter expression with a GreaterThan
logical operator is to be defined, the RadListViewGreaterThanFilterExpression
type is there to help you build the expression. The same goes for all the other
filter operators (functions).
The filter expressions can be added to RadListView's FilterExpressions collection
in several ways:
- there is the conventional approach of creating instances of the new filter expressions
and adding them to the FilterExpressions collection:
RadListView1.FilterExpressions.Add( new RadListViewGreaterThanFilterExpression<DateTime>("ShippedDate"){CurrentValue = DateTime.Parse("7/10/1996")});
RadListView1.FilterExpressions.Add( new RadListViewEqualToFilterExpression<int>("OrderID"){CurrentValue = 42} );
- alternatively, the FilterExpressions collection exposes a so-called fluent
expression builder object which, as it name supposes, can be used to build
the expressions in a more stream-lined manner:
RadListView1.FilterExpressions.BuildExpression().GreaterThan("ShippedDate", DateTime.Parse("7/10/1996")).Or().EqualTo("OrderID", 42).Build();
An improtant detail to note with this approach is the obligatory call to the Build()
method.
- the last and most consise way is provided by an overload of the FilterExpressions
collection BuildExpression property takes in an Action delegate:
RadListView1.FilterExpressions.BuildExpression(expression => expression.GreaterThan("ShippedDate", DateTime.Parse("7/10/1996")).Or().EqualTo("OrderID", 42)));
One of RadListView's most powerful filtering features is the easy way to tie several
filter expressions into one group and treat it as a single expression that can participate
in further logcial operations. Again a dedicated type is provided out-of-the-box
to help you in this regard - the RadListViewGroupFilterExpression.
It can be used in all of the above ways to construct filter expressions and add
them to the FilterExpressions collection of the RadListView control. The sample
filter expressions above can be extended with the group feature as follows:
RadListView1.FilterExpressions.BuildExpression(expression => expression.GreaterThan("ShippedDate",
DateTime.Parse("7/10/1996")).Or().EqualTo("OrderID", 42).And().Group(group => group.IsNotEmpty("ShipCountry") .And().Contains("ShipCountry", "G")));