ASPxGridView - How to apply Custom Function Filter Criteria Operator

本文介绍如何在ASPxGridView中应用自定义函数过滤器准则运算符,通过更新FilterExpression并设置自定义准则运算符值,实现复杂的过滤场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ASPxGridView - How to apply Custom Function Filter Criteria Operator

Tags:

Some complicated filter cases require visiting every leaf of the filter criteria tree when a custom function criteria operator is used.
This example shows how it can be implemented via CriteriaPatchBase's class descendant.
The main idea is to operate with ASPxGridView's FilterExpression:

1. If FilterExpression has a custom function operator, it's necessary to find exactly this custom operator and replace its value with an actual one.
In the case of Auto Filter Row, this can be done in the ASPxGridView.ProcessColumnAutoFilter event handler as shown below:

 

[C#]

protected void Grid_ProcessColumnAutoFilter(object sender, DevExpress.Web.ASPxGridViewAutoFilterEventArgs e) { var grid = (ASPxGridView)sender; if(e.Column.FieldName == SpecialFilterColumnFieldName && e.Kind == GridViewAutoFilterEventKind.CreateCriteria) { grid.FilterExpression = UpdateGridFilterExpression(grid, e); e.Criteria = null; } }

Note that e.Criteria in this case must be set to null.

2. Then, assign the custom criteria operator value to the filter editor.
The right place of the code to do this is the ASPxGridView.AutoFilterCellEditorInitialize event handler. For example, it can be implemented in the following manner:

 

[C#]

protected void Grid_AutoFilterCellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e) { var grid = (ASPxGridView)sender; if(e.Column.FieldName == SpecialFilterColumnFieldName) { var gridCriteria = CriteriaOperator.Parse(grid.FilterExpression); e.Editor.Value = CriteriaVisitor.GetCustomFunctionOperatorValue(gridCriteria, e.Column.FieldName); } }

where CriteriaVisitor  is CriteriaPatchBase's class descendant (see implementation details).

See also:
The base implementation of the IClientCriteriaVisitor interface for the CriteriaOperator expression patcher

Description

The CriteriaVisitor  class provides only two public static methods: **RemoveCustomFunction**and GetCustomFunctionOperatorValue.
The first one returns CriteriaOperator without a custom operator; the second one returns a string value of a custom function criteria operator.
There are also two overridden methods: VisitFunction and VisitGroup. They return specific values depending on the VisitorMode(LookingOnlyForCustomOperator or RemoveCustomOperator).
The IsMyCustomFunctionOperator method allows determining whether FunctionOperator is exactly that custom one (MyCustomFunctionOperator).

The MyCustomFunctionOperator  class contains some custom filtering logic, which is implemented in the **Evaluate**method.

Files to look at:

• CriteriaPatcherBase.cs (VB: CriteriaPatcherBase.vb)
• CriteriaVisitor.cs (VB: CriteriaVisitor.vb)
• MyCustomFunctionOperator.cs (VB: MyCustomFunctionOperator.vb)
• Default.aspx (VB: Default.aspx)
• Default.aspx.cs (VB: Default.aspx.vb)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值