Apply this attribute to a business class to specify a filter for the List View that will display this class’ objects. The specified filter will be loaded to the Application Model as a child node of the appropriate Filters node. All the filters added to a ListView node are represented by the built-in SetFilter Action’s items in the drop-down window. An end-user can select an item to apply the required filter to the current List View.
using DevExpress.ExpressApp.Model;
using DevExpress.ExpressApp.SystemModule;
//...
[DefaultClassOptions]
[ListViewFilter("Today", "GetDate([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", @"GetDate([DueDate]) > LocalDateTimeLastWeek() AND
GetDate([DueDate]) <= ADDDAYS(LocalDateTimeLastWeek(), 5)")]
[ListViewFilter("This week", @"GetDate([DueDate]) > LocalDateTimeThisWeek() AND
GetDate([DueDate]) <= ADDDAYS(LocalDateTimeThisWeek(), 5)")]
public class Task : BaseObject {
[ModelDefault("EditMask","d")]
public virtual DateTime DueDate { get; set; }
}
// Make sure that you use options.UseChangeTrackingProxies() in your DbContext settings.
using DevExpress.ExpressApp.Model;
using DevExpress.ExpressApp.SystemModule;
//...
[DefaultClassOptions]
[ListViewFilter("Today", "GetDate([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", @"GetDate([DueDate]) > LocalDateTimeLastWeek() AND
GetDate([DueDate]) <= ADDDAYS(LocalDateTimeLastWeek(), 5)")]
[ListViewFilter("This week", @"GetDate([DueDate]) > LocalDateTimeThisWeek() AND
GetDate([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); }
}
}
Imports DevExpress.ExpressApp.Model
Imports DevExpress.ExpressApp.SystemModule
'...
<DefaultClassOptions>
<ListViewFilter("Today", "GetDate([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", "GetDate([DueDate]) > LocalDateTimeLastWeek() AND
GetDate([DueDate]) <= ADDDAYS(LocalDateTimeLastWeek(), 5)")>
<ListViewFilter("This week", "GetDate([DueDate]) > LocalDateTimeThisWeek() AND
GetDate([DueDate]) <= ADDDAYS(LocalDateTimeThisWeek(), 5)")>
Public Class Task
Inherits BaseObject
Public Sub New(ByVal session As Session)
MyBase.New(session)
End Sub
Private fDueDate As DateTime
<ModelDefault("EditMask","d")> _
Public Property DueDate() As DateTime
Get
Return fDueDate
End Get
Set(ByVal value As DateTime)
SetPropertyValue(NameOf(DueDate), fDueDate, value)
End Set
End Property
End Class
For details, see ListViewFilterAttribute.
The filters specified via the ListView Filter attribute are added to all autogenerated ListView nodes whose ModelClass attribute is set to the class to which the attribute is applied. The attribute does not add filters to nodes that are created manually or cloned in the Model Editor. The SetFilter Action is activated for root and nested List Views, since only the Main Form Templates and Detail Form Templates contain the Filters Action Container that displays this Action.
See Also