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

ListEditCustomFilteringEventArgs.CustomHighlighting Property

Specifies rules according to which the editor highlights the filtered items.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v20.2.dll

NuGet Package: DevExpress.Web

Declaration

public ListEditCustomHighlighting CustomHighlighting { get; set; }

Property Value

Type Description
ListEditCustomHighlighting

The highlighting rules.

Remarks

The editor highlights the first occurrence of the filter string. Use the CustomHighlighting property to specify rules according to which the editor highlights the filtered items.

You can specify the CustomHighlighting property in the following ways:

  • Highlights all instances of the “str” string in the filtered items.

    e.CustomHighlighting = "str";
    
  • Highlights all instances of the “str1” and “str2” strings in the filtered items.

    e.CustomHighlighting = new string[] { "str1", "str2" };
    
  • Highlights all instances of the “str1” string in the “Column1” and the “str2” string in the “Column2” among the filtered items.

    e.CustomHighlighting = new Dictionary<string, string>() {
        { "Column1", "str1" },
        { "Column2", "str2" }
    };
    
  • Highlights all instances of the “str1” and “str2” strings in the “Column1” and the “str3” and “str4” strings in the “Column2” among the filtered items.

    e.CustomHighlighting = new Dictionary<string, string[]>() {
        { "Column1", new string[] {"str1", "str2" } },
        { "Column2", new string[] { "str3", "str4" } }
    };
    

The following code snippets illustrate how to use a regular expression to specify the CustomHighlighting property. Set the ListEditCustomHighlighting.StringToRegularExpression property to true to convert the specified string into the regular expression on the client side. Otherwise, the editor gets this regular expression as a string.

Note

Note that the CustomHighlighting property does not support the regular expression for the String array (string[]) and Dictionary with String array as a value (Dictionary<string, string[]>).

  • Highlights the “text” string followed by one or more occurrences of the “a”, “b” and “c” letters among the filtered items.

    e.CustomHighlighting = "text[a-c]+";
    e.CustomHighlighting.StringToRegularExpression = true;
    
  • Highlights the “text” string followed by one or more occurrences of the “a”, “b” and “c” letters in the “Column1” and the number “50” followed by digits between 0 and 9 in the “Column2” among the filtered items.

    e.CustomHighlighting = new Dictionary<string, string>() { { "Column1", "text[a-c]+" }, { "Column2", "50[0-9]" } }
    e.CustomHighlighting.StringToRegularExpression = true;
    

Example

The following example illustrates how to use the CustomFiltering event to filter the combo box items by several words through multiple columns:

Web Forms:

Run Demo: ASPxComboBox - Custom Filtering

<dx:ASPxComboBox ID="ComboBox1" runat="server" EnableCallbackMode="true" IncrementalFilteringMode="Contains"
    OnCustomFiltering="ComboBox1_CustomFiltering">
    <Columns>
        <dx:ListBoxColumn FieldName="CompanyName" Width="100%" />
        <dx:ListBoxColumn FieldName="Country" Width="70px" />
    </Columns>
</dx:ASPxComboBox>
protected void ComboBox1_CustomFiltering(object sender, DevExpress.Web.ListEditCustomFilteringEventArgs e) {
    string[] words = e.Filter.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    string[] columns = new string[] { "CompanyName", "Country" };
    e.FilterExpression = GroupOperator.And(words.Select(w => 
        GroupOperator.Or(
            columns.Select(c => 
                new FunctionOperator(FunctionOperatorType.Contains, new OperandProperty(c), w)
            )
        )
    )).ToString();
    e.CustomHighlighting = columns.ToDictionary(c => c, c => words);
}

MVC:

Run Demo: MVC ComboBox - Custom Filtering

@Html.DevExpress().ComboBox(settings => {
    settings.Name = "cmbWithServerFiltering";
    settings.Properties.Columns.Add(column => {
        column.FieldName = "CompanyName";
    });
    settings.Properties.Columns.Add(column => {
        column.FieldName = "Country";
    });
    <!-- ... -->
    settings.CustomFiltering += (s, e) => {
        string[] words = e.Filter.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        string[] columns = new string[] { "CompanyName", "Country" };
        e.FilterExpression = GroupOperator.And(words.Select(w => 
            GroupOperator.Or(
                columns.Select(c => 
                    new FunctionOperator(FunctionOperatorType.Contains, new OperandProperty(c), w)
                )
            )
        )).ToString();
        e.CustomHighlighting = columns.ToDictionary(c => c, c => words);    
    };
}).BindList(Model).GetHtml()

Result:

ASPxComboBox-CustomFilteringEvent

See Also