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.

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.

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.

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

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("DueDate", ref dueDate, value);      }
   }
}

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

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