Edit this page

Setting Filters Programmatically

RadVirtualGrid includes FilterDescriptors property which stores filter descriptors used for filtering operation. The most important classes are:

  • FilterDescriptor: Implements filtering property (field) name, filtering operator and value. Used to define simple filtering expressions like Country = "Germany".

  • CompositeFilterDescriptor: A collection of multiple filter descriptors with logical operator. Used to define complex filtering expressions like (Country = "Germany" AND (City = "Berlin" OR City = "Aachen")) .

caution

Before proceeding with this article, please refer to the Filtering Overview article which demonstrates how to achieve the filtering functionality in RadVirtualGrid.

Simple descriptors

FilterDescriptor's major properties:

  • PropertyName: defines the field, which values will be filtered.

  • Operator: allows you to define the type of operator. The possible values are: Contains, Does not contain, Starts with, Ends with, Equals, Not equal to, Is null, Is not null.

  • Value: the value your data will be compared against.

When you add a new descriptor to the collection, the data is automatically filtered according to it.

virtualgrid-setting-filters-programmatically 001

Using simple filter descriptor


FilterDescriptor filter = new FilterDescriptor();
filter.PropertyName = "ContactName";
filter.Operator = FilterOperator.StartsWith ;
filter.Value = "p";
filter.IsFilterEditor = true;
 this.radVirtualGrid1.FilterDescriptors.Add(filter);

Dim filter As New FilterDescriptor()
filter.PropertyName = "ContactName"
filter.[Operator] = FilterOperator.StartsWith
filter.Value = "p"
filter.IsFilterEditor = True
Me.RadVirtualGrid1.FilterDescriptors.Add(filter)

Composite descriptors

To filter a single data field by multiple values, you have to use the CompositeFilterDescriptor object. It contains a collection of filter descriptors objects and the logical operator for that filters.

virtualgrid-setting-filters-programmatically 002

Using CompositeFilterDescriptor


CompositeFilterDescriptor compositeFilter = new CompositeFilterDescriptor();
compositeFilter.FilterDescriptors.Add(new FilterDescriptor("ContactName", FilterOperator.StartsWith,"p"));
compositeFilter.FilterDescriptors.First().IsFilterEditor = true;
compositeFilter.FilterDescriptors.Add(new FilterDescriptor("CompanyName", FilterOperator.Contains, "w"));
compositeFilter.LogicalOperator = FilterLogicalOperator.And;
this.radVirtualGrid1.FilterDescriptors.Add(compositeFilter);

Dim compositeFilter As New CompositeFilterDescriptor()
compositeFilter.FilterDescriptors.Add(New FilterDescriptor("ContactName", FilterOperator.StartsWith, "p"))
compositeFilter.FilterDescriptors.First().IsFilterEditor = True
compositeFilter.FilterDescriptors.Add(New FilterDescriptor("CompanyName", FilterOperator.Contains, "w"))
compositeFilter.LogicalOperator = FilterLogicalOperator.[And]
Me.RadVirtualGrid1.FilterDescriptors.Add(compositeFilter)

See Also

Was this article helpful? Yes No
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article

close
Dummy