Edit this page

Search as You Type

Showing the Search Panel

As of R1 2016, RadGridView supports searching. Through the new boolean ShowSearchPanel property of the control, the user can show/hide the search panel. Its default value is False. If hidden, the search panel can be shown with the Ctrl+F shortcut.

The default searching behavior has two ways of setting the operator of the filtering criteria, depending on the value type of the property over which the search is performed. For a string type the operator is set to Contains. For all other types the operator is set to IsEqualTo.

Example 1: Showing the Search Panel

<telerik:RadGridView ItemsSource="{Binding Orders}"     
                         ShowSearchPanel="True"
                         Name="orderItemsDataGrid" Margin="5" 
                         AutoGenerateColumns="False" 
                         ColumnWidth="*"/>

Figure 1: Showing the Search Panel

Showing the Search Panel

Disable showing the Search Panel

You can control whether the users can use the Search Panel through the CanUserSearch boolean property of RadGridView. Its default value is true. Setting it to false would permanently disable the functionality, meaning that the Ctrl + F combination would not show the panel as well.

Example 2: Disabling the Search Panel

<telerik:RadGridView ItemsSource="{Binding Orders}"     
                         CanUserSearch="False"
                         Name="orderItemsDataGrid" Margin="5" 
                         AutoGenerateColumns="False" 
                         ColumnWidth="*"/>

Deferred Searching

The deferred searching functionality can be controlled through the IsSearchingDeferred property. Its default value is False and it determines whether the filtering through the search text box will be performed dynamically.

When IsSearchingDeferred is set to True, the filtering will be executed when the value is being committed on lost focus or when the Enter or Tab key is pressed.

Example 3: Setting the IsSearchingDeferred to True

<telerik:RadGridView ItemsSource="{Binding Orders}"
                 IsSearchingDeferred="True"
                 Name="orderItemsDataGrid" 
                 Margin="5" 
                 AutoGenerateColumns="False"/>

Commands

Two new commands have been exposed for the text search functionality.

  • Search: Executed in order to show the search panel.

  • CloseSearchPanel: Executed in order to hide the search panel.

Events

As of R2 2016, the SearchPanelVisibilityChanged event will be raised on changing the ShowSearchPanel property. Its arguments are of type VisibilityChangedEventArgs and contain the value of the new visibility - NewVisibility.

A common scenario where you can use this event is when you want to clear the search criteria on collapsing the panel:

Example 4: Clearing search criteria on SearchPanelVisibilityChanged

public MainWindow()
{
    InitializeComponent();
    this.RadGridView.SearchPanelVisibilityChanged += RadGridView_SearchPanelVisibilityChanged;
}

void RadGridView_SearchPanelVisibilityChanged(object sender, VisibilityChangedEventArgs e)
{
    if (e.NewVisibility == Visibility.Collapsed)
    {
        var clearSearchValue = GridViewSearchPanelCommands.ClearSearchValue as RoutedUICommand;
        clearSearchValue.Execute(null, this.RadGridView.ChildrenOfType<GridViewSearchPanel>().FirstOrDefault());
    }
}
Public Sub New()
    InitializeComponent()
    AddHandler Me.RadGridView.SearchPanelVisibilityChanged, AddressOf RadGridView_SearchPanelVisibilityChanged
End Sub

Private Sub RadGridView_SearchPanelVisibilityChanged(sender As Object, e As VisibilityChangedEventArgs)
    If e.NewVisibility = Visibility.Collapsed Then
        Dim clearSearchValue = TryCast(GridViewSearchPanelCommands.ClearSearchValue, RoutedUICommand)
        clearSearchValue.Execute(Nothing, Me.RadGridView.ChildrenOfType(Of GridViewSearchPanel)().FirstOrDefault())
    End If
End Sub

Modifying the Searching Criteria

In order to modify the search behavior, you can benefit from the following three search operators:

  • +: The items that will pass the filtering operation will have to contain both the value before the operator and the one after it.

    Figure 2: Using the __+ search operator__

    Using the + search operator

  • -: All items that will pass the filtering operation will have to contain the value before the operator, but not the one after it.

    Figure 3: Using the __- search operator__

    Using the - search operator

  • "": When a word or a phrase is put in quotes, the filtered objects will contain only the exact same value.

    Figure 4: Using the "" search operator

    Using the "" search operator

Change the Label Text of the Search Panel

By default, the value of the TextBlock appearing before the Search TextBox in the SearchPanel is "Full Text Search". It can be altered through the Localization mechanism of RadGridView. The resource key that needs to be modified is GridViewSearchPanelTopText. More information can be found in the Localization topic.

Add Search Criteria Programmatically

RadGridView's search mechanism supports defining a search criteria programmatically. This can be done through the SearchByText Command. More information can be found in the Commands Overview topic.

See Also