Skip to main content
.NET 8.0+

ListViewFilter Attribute

  • 3 minutes to read

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.

For details, see ListViewFilterAttribute.

Note

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 MainForm and DetailViewForm Windows Forms Templates and the Default ASP.NET Web Forms Template contain the Filters Action Container that displays this Action.

See Also