Skip to main content

AutoCompleteBoxBaseSettings.CustomFiltering Property

Enables you to specify filtering rules before the server-side filtering.

Namespace: DevExpress.Web.Mvc

Assembly: DevExpress.Web.Mvc5.v24.2.dll

Declaration

public ListEditCustomFilteringEventHandler CustomFiltering { get; set; }

Property Value

Type Description
ListEditCustomFilteringEventHandler

A delegate method that allows you to implement custom filtering.

Remarks

Use the delegate specified by the CustomFiltering property to filter the editor items. The delegate receives an argument of the ListEditCustomFilteringEventArgs type. The argument’s properties contains data specific to this delegate.

The editor uses the “Contains/Starts with” comparison operator if the ListEditCustomFilteringEventArgs.FilterExpression property is not specified. The ListEditCustomFilteringEventArgs.FilterExpression property is not in effect if the combo box is in custom binding mode.

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

The editor reraises a delegate specified by the CustomFiltering property if items are loaded on a callback when scrolling. In this case, the ListEditCustomFilteringEventArgs.CustomHighlighting property is not in effect.

Note

The CustomFiltering property is not in effect in the following cases:

Run Demo: MVC ComboBox - Custom Filtering

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

@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:

ComboBox Custom Filter

See Also