Search Panel

  • 6 min to read

The Search Panel allows end-users to locate data by typing the filter criterion in the panel editor and highlight the search results.

To enable the search panel, set the ASPxGridSearchPanelSettings.Visible property to true. To access the panel settings, use the ASPxTreeList.SettingsSearchPanel property.

A search panel filter criterion is automatically applied after a certain time period (ASPxGridSearchPanelSettings.Delay) by default. Disable the time delay by setting the ASPxGridSearchPanelSettings.AllowTextInputTimer property to false. In this case, the filter criterion is not automatically applied. An end-user can click the Apply (Search) button or press the ENTER key to apply the entered criterion.

ASPxTreeList-SearchPanel

NOTE

Search Panel Limitations * Search results contained in templates are not highlighted automatically. However, you can implement the highlighting manually.

  • The search panel highlighting may break the current HTML structure when tree list text contains HTML tags and the EncodeHtml property is set to false.

    According to the searching logic, the ASPxTreeList obtains all the text from a database field, determines matches and wraps all matches in a span element to highlight them. When the EncodeHtml property is set to false, this logic may break the current HTML structure. You can either disable ASPxGridSearchPanelSettings.HighlightResults or define a TreeListDataColumn.DataCellTemplate for this column to prevent highlighting if an entered text contains HTML parts.

How to apply a search panel filter in code

You can apply a search panel filter in code on the server and client side.

On the server side

The code sample below demonstrates how to specify the search panel filter in code on the server side using the ASPxTreeList.SearchPanelFilter property.

SearchPanel_SearchPanelFilter

<dx:ASPxTreeList ID="TreeList" runat="server" DataSourceID="TreeListDataSource" >
     <Columns>
          ...
     </Columns>
     <SettingsSearchPanel Visible="true" ShowApplyButton="True" ShowClearButton="True" />
</dx:ASPxTreeList>
TreeList.SearchPanelFilter = "big";

On the client side

The code sample below demonstrates how to specify the search panel filter in code on the client side using the ASPxClientTreeList.ApplySearchPanelFilter method.

SearchPanel_SearchPanelFilter

<dx:ASPxTreeList ID="TreeList" runat="server" DataSourceID="TreeListDataSource" 
ClientInstaceName="treelist" >
     <Columns>
          ...
     </Columns>
     <SettingsSearchPanel Visible="True" ShowApplyButton="True" ShowClearButton="True" />
</dx:ASPxTreeList>
treelist.ApplySearchPanelFilter('big');
NOTE

The ASPxTreeList.SearchPanelFilter property and ASPxClientTreeList.ApplySearchPanelFilter method are in effect even if the search panel is disabled (the ASPxGridSearchPanelSettings.Visible property is set to false).

How to specify the columns to which the search panel filter is applied

The search panel filter is applied to all visible data columns in the tree list by default.

To apply the filter to particular columns, use the TreeListSettingsSearchPanel.ColumnNames property. The property lists column identifiers that can be either a column name (WebColumnBase.Name), field name (TreeListDataColumn.FieldName), or caption(WebColumnBase.Caption).

SearchPanel_ColumnName

<dx:ASPxTreeList ID="TreeList" runat="server" DataSourceID="TreeListDataSource">
          <Columns>
               <dx:TreeListDataColumn FieldName="ContactName" />
               <dx:TreeListDataColumn FieldName="CompanyName"/>
               <dx:TreeListDataColumn FieldName="Address" />
               <dx:TreeListDataColumn FieldName="City" />
               <dx:TreeListDataColumn FieldName="Country" />
          </Columns>
     <SettingsSearchPanel Visible="true" ShowApplyButton="True" ShowClearButton="True" ColumnNames="ContactName; CompanyName" />
     ...
</dx:ASPxTreeList>

To exclude a particular column from filtering, set the column's TreeListDataColumn.AllowFilterBySearchPanel property to false.

SearchPanel_AllowFilterBySearchPanel

<dx:ASPxTreeList ID="TreeList" runat="server" DataSourceID="TreeListDataSource" AutoGenerateColumns="False">
     <Columns>
          <dx:TreeListDataColumn FieldName="ContactName" />
          <dx:TreeListDataColumn FieldName="CompanyName">
               <Settings AllowFilterBySearchPanel="False" />
          </dx:TreeListDataColumn>
          <dx:TreeListDataColumn FieldName="Address" />
          <dx:TreeListDataColumn FieldName="City" />
          <dx:TreeListDataColumn FieldName="Country" />
     </Columns>
     <SettingsSearchPanel Visible="true" ShowApplyButton="True" ShowClearButton="True" />
     ...
</dx:ASPxTreeList>

How to change the default search panel editor with a custom one

ASPxTreeList allows replacing the default editor with another DevExpress editor in the ASPxTreeList.SearchPanelEditorCreate event handler.

SearchPanel_EditorCreate

<dx:ASPxTreeList ID="TreeList" runat="server" DataSourceID="TreeListDataSource" OnSearchPanelEditorCreate="TreeList_SearchPanelEditorCreate">
     <Columns>
     ...
     </Columns>
     <SettingsSearchPanel Visible="true" ShowApplyButton="True" ShowClearButton="True" />
     ...
</dx:ASPxTreeList>
protected void TreeList_SearchPanelEditorCreate(object sender, DevExpress.Web.ASPxTreeListSearchPanelEditorCreateEventArgs e) {
     e.EditorProperties = new SpinEditProperties();
}

Alternatively, specify an external DevExpress editor with the ASPxGridSearchPanelSettings.CustomEditorID property.

SearchPanel_CustomEditorID

<dx:ASPxTreeList ID="TreeList" runat="server" DataSourceID="TreeListDataSource">
     <Columns>
          ...
     </Columns>
     <SettingsSearchPanel CustomEditorID="ASPxTextBox1" />
     ...
</dx:ASPxTreeList>

<dx:ASPxTextBox ID="ASPxTextBox1" runat="server" Width="170px">
</dx:ASPxTextBox>

Search syntax

In its simplest form, a search criterion consists of a single word. However, the search panel allows you to create composite criteria.

Search Criteria

Sample Image

Description

Mask:

criterion

Example:

maria

EUD_Grid_SearchPanelCriterion1

Example description: selects records that contain the "maria" string in any search column.

Mask:

column:criterion

Example:

contact:maria

EUD_Grid_SearchPanelCriterion2

End-users can search against a specific column by preceding a search string with the column's caption plus a colon character. Instead of the complete caption, it is possible to use the caption's initial characters to perform a search against the first column whose name starts with the specified substring. To search against a column whose caption contains space characters, specify the column's display caption in quotation marks.

If the search string contains multiple conditions separated by space characters, and at least one condition defines a search against a specific column, the tree list displays only records that match all of these conditions (conditions are combined by the AND logical operator).

Example description: selects records that contain "maria" in the column that starts with "contact".

Mask:

criterion1 criretion2

Example:

maria anders

Option 1

EUD_Grid_SearchPanelCriterion3_v2

Option 2

EUD_Grid_SearchPanelCriterion3

If the search string contains multiple words separated by space characters, the words are considered as individual conditions. Use the ASPxGridSearchPanelSettings.GroupOperator property to specify a logical operator used to combine the conditions.

Option 1 (default behavior)

When the ASPxGridSearchPanelSettings.GroupOperator property is set to And.

Only records that match all of the conditions are shown (that is, the conditions are combined by the AND logical operator).

Example description: selects records that contain both "maria" AND "anders" strings in any search column.

Option 2

When the ASPxGridSearchPanelSettings.GroupOperator property is set to Or.

If there is no column specification, the tree list displays records that match at least one of these conditions (the conditions are combined by the OR logical operator). If at least one condition defines a search against a specific column, the tree list displays only records that match all of these conditions (conditions are combined by the AND logical operator).

Example description: selects records that contain either "maria" OR "anders" strings in any search column.

Mask:

"criterion with spaces"

Example:

"maria anders"

EUD_Grid_SearchPanelCriterion4

If you want to search for a string containing a space character, specify this string in quotation marks.

Example description: selects records that contain "maria anders" in any search column.

Mask:

criterion1 -criterion2

Example:

maria -anders

EUD_Grid_SearchPanelCriterion5

Precede a condition with "-" to exclude records that match this condition from the resulting set. There should be no space between the "-" sign and the condition.

Example description: selects records that contain "maria", excluding records that contain "anders".

Mask:

criterion1 +criterion2

Example:

maria +sweden

EUD_Grid_SearchPanelCriterion6

Precede a condition with "+" to display only records that match this condition. The "+" specifier allows implementing the logical AND operator. There should be no space character between the "+" sign and the condition.

Example description: selects records that contain both "maria" AND "sweden" in search columns.

NOTE

Searches performed using a Search Panel are case insensitive.

Online Demos

See Also