ListViewFilterAttribute Class
Specifies the filters that an end-user will be able to apply to the List View that displays the target class’objects.
Namespace: DevExpress.ExpressApp.SystemModule
Assembly:
DevExpress.ExpressApp.v24.2.dll
Declaration
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface, AllowMultiple = true)]
public class ListViewFilterAttribute :
Attribute
<AttributeUsage(AttributeTargets.Class Or AttributeTargets.Struct Or AttributeTargets.Interface, AllowMultiple:=True)>
Public Class ListViewFilterAttribute
Inherits Attribute
The following example demonstrates how to apply the ListViewFilter attribute:
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
The XAF is shipped with the SetFilter Action (see FilterController.SetFilterAction). This Action is displayed as a combo box, whose items represent filter captions. When an end-user selects an item, the current List View is filtered.

To add items to this Action, apply the ListViewFilter attribute to the business class whose List Views are to be filtered. Pass the required ListViewFilterAttribute.Caption, ListViewFilterAttribute.Criteria, ListViewFilterAttribute.Description and other filter details via the attribute’s parameters.
You can add as many ListViewFilter attributes as you wish to the target business class. The filters specified by these attributes will be loaded to the Application Model. The Filter child nodes will be added to the corresponding Views | <ListView> | Filters node. You can modify these filters via the Model Editor. In addition, you can add new filters via the Views | <ListView> | Filters node’s context menu. For details, refer to the Filters Application Model Node topic.
View Example: XAF - How to show filter dialog before a List View
See Also