New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Filter separate columns with OR logic; create custom filtering logic

HOW TO

Change the filtering of RadGrid so different columns filters are used with an OR logic instead of the default AND logic.

DESCRIPTION

RadGrid uses AND logic for filters coming from separate columns. There isn't a built-in feature that allows you to change that, so you need to create your own filtering expression.

SOLUTIONS

The solution boils down to creating a filter expression that will produce the desired results with the data source that you have.

There are two general ways to do this:

  • Modify the FilterExpression of the table view and set the filters to the columns. This is showcased in the sample attached below.
  • Filter the data source before providing it to the grid in the NeedDataSource event. A similar approach is used in the Custom Paging demo. You can see what filter expressions the grid provides in the Edit this page Operate with the FilterExpression Manually help article.

TIPS

You can use an approach similar to the Filter Templates demo and fire a custom command instead of using a button. This lets you invoke the same functionality in the ItemCommand handler by checking for your custom command name.

If you want to pre-filter the grid for your end user, you can either filter the data source, or use the approach from the Apply Default Filter on Initial Load Knowledge-Base article.

Using an OR operator for filtering several values in one column is supported out of the box in the Excel-like filtering where you can check several values that you want present in the filtered data for that column.

DOWNLOADS

A runnable page that shows the approach in action is attached here:

In this article