Search and Filtering
Data Grid supports the data filtering and searching features, which allow you to locate rows that contain specific text.
Search Panel
The Search Panel helps a user quickly locate rows by the data they contain. When a user types text in the Search Panel, the Data Grid control displays those rows that contain the typed text in any cell.
Set the control's SearchPanelDisplayMode
property (inherited from the DataControlBase
class) to one of the following values to enable the Search Panel:
SearchPanelDisplayMode.Always
— The control permanently displays the Search Panel.SearchPanelDisplayMode.HotKey
— The control displays the Search Panel when a user presses the CTRL+F hotkey. The ESC shortcut clears the Search Panel. A subsequent ESC key press closes the panel. A user can also activate the Search Panel from a column header's context menu.
The search functionality is case-insensitive.
Related API
DataControlBase.IsSearchPanelVisible
— Gets whether the Search Panel is currently visible.DataControlBase.SearchPanelHighlightResults
— Specifies whether to highlight the search text in the found rows. The property's default value istrue
.DataControlBase.SearchText
— Gets or sets the search text. You can assign a value to this property to filter the control in code. This filtering functionality is supported even if the Search Panel is hidden or disabled (theSearchPanelDisplayMode
property is set toSearchPanelDisplayMode.Never
).DataControlBase.ShowSearchPanelCloseButton
— Allows you to hide the Search Panel's built-in Close button.
Example
The following code enables the Search Panel. The SearchText
property is used to set the search text.
dataGrid.SearchPanelDisplayMode = SearchPanelDisplayMode.Always;
dataGrid.SearchText = "search";
Auto Filter Row
The Auto Filter Row is a special row displayed above all grid rows. It allows a user to type text in its cells to filter data against corresponding columns.
Set the DataGridControl.ShowAutoFilterRow
property to true
to enable the Auto Filter Row.
You can use the ColumnBase.AutoFilterCondition
property to specify the data comparison operation for specific cells (columns) of the Auto Filter Row. When a user types text, the Data Grid control uses the specified comparison operation to compare column values while locating target rows. The following data comparison operations are supported:
Equals
— Row values in the target column should match the entered value.Contains
— Row values in the target column should contain the entered value. This mode is appropriate for String values.StartsWith
— Row values in the target column should start with the entered value. This mode is appropriate for String values.Default
— TheDefault
option is equivalent to theContains
option for the String and Object data types. This option is equivalent to theEquals
option for other data types.
The ColumnBase.AutoFilterValue
property allows you to set a value for a specific Auto Filter Row cell in code. You can use the ColumnBase.AutoFilterValue
to filter the Data Grid even if the Auto Filter Row is hidden.
The filter functionality is case-insensitive.
Example
The following code activates the Auto Filter Row, and displays rows whose values in the 'Name' column start with "M".
using Eremex.AvaloniaUI.Controls.DataControl;
using Eremex.AvaloniaUI.Controls.DataGrid;
dataGrid1.ShowAutoFilterRow = true;
GridColumn colName = dataGrid1.Columns["Name"];
colName.AutoFilterCondition = AutoFilterCondition.StartsWith;
colName.AutoFilterValue = "M";
Filter in Code
The DataControlBase.SearchText
and ColumnBase.AutoFilterValue
properties can be used to filter the Data Grid control in code, even if the Search Panel and Auto Filter Row are hidden.
If you use the DataControlBase.SearchText
property, the Data Grid filters rows by searching for the entered text in all columns. The Contains
comparison operation is used.
If you use the ColumnBase.AutoFilterValue
property, the Data Grid searches for the entered text in the specified column. The ColumnBase.AutoFilterCondition
property defines the comparison operation.