Skip to main content
A newer version of this page is available. .

Filter and Search

  • 13 minutes to read

When a filter is applied, the View displays only those records that meet the current filter criteria. You can filter data against one or multiple columns.

Most DevExpress data-aware components (Data Grid, Tree List, Vertical Grid, etc.) have the filtering UI and API similar to that described in this topic.

Filtering Dropdown Menus (Excel Style)

To invoke a filtering dropdown menu for a column, click the filter icon within the column header. In the “Values” tab, end-users can select specific cell values from those that are currently displayed by the Data Grid.

Grid - Excel Filter Dropdown Menu Values

The “Filters” tab gives users a wider pool of filtering options. For example, when filtering by dates, you can only show those records that correspond to the previous week.

Grid - Excel Filter Dropdown Menu

The content of a filtering dropdown menu depends on the type of data displayed by the related grid column. For instance, the figure below illustrates what this menu looks like when filtering by a numeric column.

Grid - Excel Filter Dropdown Menu Numeric Data

This type of filtering dropdown menus is called Excel-style dropdowns and is the default filtering menu type starting with version 17.1.

Related API

See the Advanced Filter and Search Concepts article to learn how to dynamically customize Excel-style menus.

Classic Filtering Dropdown Menus

Instead of Excel-style dropdowns, the Data Grid can display classic filtering menus. These are calendars for the DateTime columns and regular dropdowns for columns of other types.

Grid - Classic Filter Dropdowns

Related API:

You can opt for checked list menus instead of regular dropdown menus.

FilterDropdown-Checked.png

Related API:

Calendar filtering menus can also be replaced with checked lists. Additionally, you can select between three types of calendar-based menus: DateSmart (default menu type), DateAlt and Date. The figure below illustrates the DateAlt menu.

CalendarFilterDropdown-DateAlt.png

All three menus feature the same calendar for selecting a specific date, but with different sets of check boxes to select non-intersecting date intervals. The table below lists some of these intervals.

DateSmart

Date

DateAlt

Check boxes are visible only if there are Data Grid records that fall into corresponding intervals.

  • Beyond this year - dates that follow the current year.
  • Later this year - dates of the current year starting with the following month.
  • Later this month - dates of the current month that follow next week.
  • Next week - dates that belong to the following week.
  • Later this week - dates of the current week starting with the day after tomorrow.
  • Earlier this week - dates of the current week that are prior to yesterday.
  • Last week - dates of the previous week.
  • Earlier this year - dates of the current year that are prior to the current month.
  • Prior to this year - dates that are prior to the current year.

Same time intervals as for the DateSmart type. All check boxes are available, even if there is no data that falls into a corresponding date range.

  • Beyond - dates that belong to the month in three months time and beyond.
  • Earlier - dates that belong to the month seven months ago and earlier.

Related API:

Automatic Filtering Row

Watch Video

Another way to filter data at runtime is to utilize the automatic filtering row. This row is displayed above regular data rows and allows end-users to type in filtering values (including ‘*’ and ‘%’ wildcards) and select filter operators (NotLike, Equals, Between, etc.).

Grid - Auto Filter Row Grid - Auto Filter Row Animation

Note that to allow users to enter any characters they wish, cell editors ignore their masks when shown in the Automatic Filtering Row. The following code demonstrates how to manually keep the numeric mask active for the Auto Filtering Row.

private void GridView1_ShownEditor(object sender, System.EventArgs e) {
    GridView view = sender as GridView;
    TextEdit edit = view.ActiveEditor as TextEdit;
    if (edit != null && view.IsFilterRow(view.FocusedRowHandle))
        edit.Properties.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.Numeric;
}

Note that if an Auto Filter Row cell uses a RepositoryItemRichTextEdit in-place editor, users can only select the “Like” filter condition for this cell. Other conditions (“Starts with”, “Equals”, etc.) are not available for RTF values.

Related API:

Filter Panel

When you apply filtering, a View shows a filter panel. End-users can utilize this panel to modify and remove current filters.

Grid - Filter Panel Layout

Related API:

End-users can focus a grid column and start typing. The Data Grid will focus and highlight the first matching record. To find other records, press Ctrl+Up and Ctrl+Down hotkeys.

Data Grid - Filtering - Incremental Search

Related API:

Filter Editor

The Filter Editor dialog allows end-users to build complex filtering criteria, combined from multiple expressions. To invoke this dialog end-users can do one of the following:

Grid - Filter Editor

You can modify the ColumnViewOptionsFilter.DefaultFilterEditorView property to enable the Filter Editor’s “Text” panel\tab, where users can type filter expressions manually.

New Filter Editor Control

Starting with version 18.1, the legacy Filter Editor is replaced with its updated version that features the advanced “Text” panel. This panel now supports syntax highlighting and auto-complete to facilitate the input. To revert data-aware controls back to the legacy Filter Editor version, disable the static WindowsFormsSettings.UseAdvancedFilterEditorControl property.

Related API:

Show example

The code below allows end-users to filter the “Price” column’s data by using the SpinEdit and CalcEdit editors.

FilterControl - Custom Editor

private void GridView1_FilterEditorCreated(object sender, DevExpress.XtraGrid.Views.Base.FilterControlEventArgs e) {
    e.FilterControl.BeforeShowValueEditor += FilterControl_BeforeShowValueEditor;
}
RepositoryItemSpinEdit reSpinEdit = new RepositoryItemSpinEdit();
RepositoryItemCalcEdit reCalcEdit = new RepositoryItemCalcEdit();
private void FilterControl_BeforeShowValueEditor(object sender, DevExpress.XtraEditors.Filtering.ShowValueEditorEventArgs e) {
    if (e.CurrentNode.FirstOperand.PropertyName != "Price") return;
    RepositoryItemTextEdit item = null;
    if (e.FocusedElementIndex == 2)
        item = reSpinEdit;
    else
        item = reCalcEdit;
    item.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.Numeric;
    item.Mask.EditMask = "c";
    e.CustomRepositoryItem = item;
}

Filter Criteria Display Style

The following list demonstrates the available display styles of filter criteria in controls.

  • Visual -

    Renders filter criteria in an easy-to-read format and uses skin-based colored highlights to differentiate between column names, functions and values. In the Filter Panel, the ‘x’ button is displayed when you hover over a condition. This button allows users to quickly remove individual conditions from the filter.

    image

  • Text -

    Renders filter criteria in a text-based format.

    image

Related API:

Find Panel

The Find Panel allows your end-users to apply a temporary filter that filters data across all Data Grid columns at once. To invoke this panel, press “Ctrl+F” at runtime. Type in text you need to search for, then press Enter or click “Find”.

Grid - Find Panel

Note that the Find Panel does not highlight cells with HTML text.

Related API:

See Find Panel to learn more.

Search in Column Headers

You can use the GridView.OptionsFilter.InHeaderSearchMode property to enable built-in search boxes within the View’s column headers. The search boxes are used to filter column data, or to search in columns, depending on the mode you choose.

‘TextFilter’ Mode

Users can type text in the search boxes to filter against the columns.

Data Grid - In-header search box - Filter mode

‘TextSearch’ Mode

Users can type text in the search boxes to search for column data. The grid highlights cell text that matches the specified search string.

Data Grid - In-header search box - Search mode

Use the following shortcuts to navigate between search results:

  • CTRL+DOWN or F3 — Navigates to the next search result.
  • CTRL+UP or SHIFT+F3 — Navigates to the previous search result.

The GridColumn.OptionsFilter.AllowInHeaderSearch property allows you to disable search boxes in individual column headers.

Search Syntax

The following list demonstrates sample search expressions supported in column header search boxes:

  • Spa — finds records whose column values contain this string (in non-numeric columns).
  • 10 - finds records whose column values are equal to “10” (in numeric columns).
  • =Spain or =22 — finds records whose column values are equal to the specified value.
  • <>40 — finds records whose column values are not equal to the specified value .

    Other supported comparison operators include: <, >, <=, >=, and != (equivalent to <>).

  • =USA,Spain,Germany or =USA;Spain;Germany — finds records whose column values are equal to any of these listed values.
  • [10:20] or [10..20] — finds records whose column values belong to the specified inclusive range.

Text search is case-insensitive.

See the following topic for more information: GridView.OptionsFilter.InHeaderSearchMode.

See Also