How to: Use Function Criteria Operators to Filter List Views 如何:使用函数条件运算符筛选列表视图

The eXpressApp Framework provides various approaches to filter List Views: on data source level, via the Application Model and on the UI specific level. In each of these approaches, you may need to set static variables as filter criteria values. For example, the filter "Task.DueDate must be set to the current date" needs the CurrentDate variable, calculated every time it is required. For this purpose, the use Function Criteria Operators. They represent functions you can use in criteria. In this topic, you will learn how to use these Function Criteria Operators when setting filter criteria for the Task List View. To see a full list of built-in Function Criteria Operators and learn how to implement custom ones, refer to the Function Criteria Operators topic.

eXpressApp 框架提供了筛选列表视图的各种方法:在数据源级别、通过应用程序模型和 UI 特定级别。在每种方法中,您可能需要将静态变量设置为筛选器条件值。例如,筛选器"Task.DueDate 必须设置为当前日期"需要"当前日期"变量,该变量在每次需要时计算。为此,使用函数条件运算符。它们表示可以在条件中使用的功能。在本主题中,您将学习如何在为任务列表视图设置筛选条件时使用这些函数条件运算符。要查看内置函数条件运算符的完整列表并了解如何实现自定义函数,请参阅函数条件运算符主题。

Since the technique for using Function Criteria Operators is common to any filtering approach, both in code and the Model Editor, the ListViewFilterAttribute will be chosen for demonstration.

由于使用函数条件运算符的技术在任何筛选方法(包括代码和模型编辑器中)中都很常见,因此将选择 ListViewFilter属性进行演示。

Note 注意
Before reviewing the example, be sure to read the "Important Remark on the DateTime Function Criteria Operators" section of the Function Criteria Operators topic.
在查看该示例之前,请务必阅读函数条件运算符主题的"日期函数条件运算符上的重要备注"部分。
 
Tip 提示
A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E3936
完整的示例项目可在 DevExpress 代码示例数据库中找到,http://www.devexpress.com/example=E3936

.

The following code demonstrates how to implement various filters using the LocalDateTimeToday, LocalDateTimeLastWeek and LocalDateTimeThisWeek Function Criteria Operators:

以下代码演示如何使用"本地日期时间今天"、LocalDateTheWeek 和 LocalDateThisthis 这一周函数条件运算符实现各种筛选器:

using DevExpress.ExpressApp.Model;
using DevExpress.ExpressApp.SystemModule;
//...
[DefaultClassOptions]
[ListViewFilter("Today", "[DueDate] = LocalDateTimeToday()")]
[ListViewFilter("In three days", "[DueDate] >= ADDDAYS(LocalDateTimeToday(), -3) AND 
    [DueDate] < LocalDateTimeToday()")]
[ListViewFilter("In two weeks", "[DueDate] >= ADDDAYS(LocalDateTimeToday(), -14) AND 
    [DueDate] < LocalDateTimeToday()")]
[ListViewFilter("The last week", "[DueDate] > LocalDateTimeLastWeek() AND 
    [DueDate] <= ADDDAYS(LocalDateTimeLastWeek(), 5)")]
[ListViewFilter("This week", "[DueDate] > LocalDateTimeThisWeek() AND 
    [DueDate] <= ADDDAYS(LocalDateTimeThisWeek(), 5)")]
public class Task : BaseObject {
   public Task(Session session) : base(session) {}
   private DateTime dueDate;
   [ModelDefault("EditMask","d")]
   public DateTime DueDate {
      get {
         return dueDate;
      }
      set {
         SetPropertyValue(nameof(DueDate), ref dueDate, value);      }
   }
}

The code above generates several Filter child nodes for the Application Model's Views | Task_ListView node:

上面的代码为应用程序模型的视图生成多个筛选器子节点 |Task_ListView节点:

FCO_ListViews

Note 注意
You could generate these nodes manually in the Model Editor.
您可以在模型编辑器中手动生成这些节点。

The following image demonstrates the Filter Action that contains all the filters provided by the code above:

下图演示了筛选器操作,其中包含上述代码提供的所有筛选器:

Read-OnlyParameters for List Views_Result

原文地址:https://www.cnblogs.com/foreachlife/p/How-to-Use-Function-Criteria-Operators-to-Filter-List-Views.html