We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to set and apply the column filter in code behind?

GridDataControl allows you to create filters and apply them from code behind in two ways,

  • Using Column filter
  • Using View filter

Column filter:

You can apply filter to a particular column by adding FilterPredicate to the Filters of that VisibleColumn using Filters.Add method.

FilterPredicate class has the following properties.

 

Property

Type

Descriptions

FilterBehavior

FilterBehavior

Determines the filter behavior of the predicate.

FilterType

FilterType

Determines the type of filter to be applied for the predicate.

FilterValue

Object

Determines the filter value to be applied for the predicate.

IsCaseSensitive

Boolean

Determines whether the predicate to be applied with the filter value is case sensitive.

PredicateType

PredicateType

Determines the relations of multiple predicates and whether they should be applied with OR or AND.

 

Filter Behavior

  • StringTyped: Records are filtered without considering the type and it takes all the types as string.
  • StronglyTyped: Records are filtered according to the underlying type.

 

Filter Type

  • Contains: Checks the records that contain the filter value.
  • EndsWith: Checks the records which end with the filter value.
  • Equals: Checks the records which are equal to the filter value.
  • GreaterThan: Checks the records which are greater than the filter value.
  • GreaterThanOrEqual: Checks the records which are greater than or equal to the filter value.
  • LessThan: Checks the records which are less than the filter value.
  • LessThanOrEqual: Checks the records which are less than or equal to the filter value.
  • NotEquals: Checks the records which are not equal to the filter value.
  • StartsWith: Checks the records which start with the filter value.
  • Between: Checks the records which have values between the filter values.

 

Predicate Type

  • AND: Applies AND operator between the predicates.
  • OR: Applies OR operator between the predicates.

 

You can set any Predicate Type and conditions available in Predicate class to a VisibleColumn’s Filter. Refer the following code example, where column filter is applied to the “Companynamecolumn with FilterType “Equals”, FilterValue Syncfusion”, and PredicateType as And”.

C#

 

Following snapshots illustrates the effect of above code in GridDataControl

D:\Syncfusion\Issues\2014 Volume 2\KB Issues\KB Images\Filtering.PNG

 

View Filters:

GridDataControl provides support to achieve view filtering by setting the GridDataControl.Model.View.Filter property. FilterRecords method filters the data that contains the filterText value. To filter a column assign, FilterRecords method to GridDataControl.Model.View.Filter predicate. Refer the following code.

C#

 

Following snapshot illustrates the effect of above code in GridDataControl

 

D:\Syncfusion\Issues\2014 Volume 2\KB Issues\KB Images\ViewFilter.PNG

 

In this example, the GridDataControl contains EmployeeDetails as ItemsSource. FilterRecords method is used to filter the filterText (filterText is the text entered in the text box in the view). FilterRecords is assigned to dataGrid.Model.View.Filter predicate to filter the “EmpName” column. Here the EmpName column is filtered using a search string “raj”.

Article ID: Published Date: Last Revised Date: Platform: Control: .NET Framework: Product Version:
2423 08/06/2014 08/06/2014 WPF GridDataControl 4 12.1.0.43
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon