ListEditCustomFilteringEventArgs.FilterExpression Property
Specifies the filter expression.
Namespace: DevExpress.Web
Assembly: DevExpress.Web.v24.2.dll
NuGet Package: DevExpress.Web
#Declaration
#Property Value
Type | Description |
---|---|
String | The filter expression. |
#Remarks
Use the FilterExpression property to specify the filter expression based on the Criteria Operator syntax.
The editor uses the “Contains/Starts with” comparison operator if the FilterExpression property is not specified. The FilterExpression property is not in effect if the combo box is in custom binding mode.
The filter expression can be based on the data object properties (columns) from the DataSource or ListEditItem properties: the item’s display text (ListEditItem.Text) or value (ListEditItem.Value).
CriteriaOperator CreateDefaultFilterExpression(string filter, IncrementalFilteringMode mode) {
if(mode == IncrementalFilteringMode.StartsWith)
return new FunctionOperator(FunctionOperatorType.StartsWith, new OperandProperty("ListEditItem.Text"), filter);
if(mode == IncrementalFilteringMode.Contains)
return new FunctionOperator(FunctionOperatorType.Contains, new OperandProperty("ListEditItem.Text"), filter);
throw new Exception();
}
Note
The Filter
#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:
<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:
@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: