学习008-02-04-02 Change List View Filters(更改列表视图过滤器)

Change List View Filters(更改列表视图过滤器)

This lesson describes three techniques you can use to filter the objects in a List View.
本课介绍了可用于过滤列表视图中对象的三种技术。

In your application, the Employee List View shows all employees at once. The instructions below show how to apply one of the following filters to this List View:
在您的应用程序中,员工列表视图一次显示所有员工。以下说明显示了如何将以下过滤器之一应用于此列表视图:

  • Display only employees from the Development department(仅显示来自开发部门的员工 )
  • Display only developers(仅显示开发者)
  • Display all employees(显示所有员工)

Note
Before you proceed, take a moment to review the previous lessons:
在继续之前,请花点时间回顾一下之前的课程:

  • Implement a Data Model: Basics
  • Implement Reference Properties
  • Configure a One-to-Many Relationship
  • How to: Implement Cascading Filtering for Lookup List Views
  • How to: Place an Action in a Different Location

Add Multiple Predefined Filters(添加多个预定义过滤器)

This technique allows end users to apply predefined filters to a List View.
这种技术允许最终用户将预定义的过滤器应用于列表视图。

1.In the MySolution.Module project, open the Model.DesignedDiffs.xafml file in the Model Editor. Navigate to the Views | MySolution.Module.BusinessObjects | Employee | Employee_ListView node. Right-click the Filters child node and select Add | ListViewFilterItem from the context menu.
在MySolutions. Module项目中,在Model Editor中打开Model.DesignedDiffs.xafml文件。导航到Views|MySolutions.Module.BusinessObjects|Employee|Employee_ListView节点。右键单击Filters子节点并从上下文菜单中选择Add|ListViewFilterItem。

When you add items to the Filters node, the built-in SetFilter Action becomes available in the UI.
当您将项目添加到过滤器节点时,内置的SetFilter Action将在UI中可用。

2.Specify the following properties for the new node:
为新节点指定以下属性:

  • Set the Id property to Development Department Employees.(将Id属性设置为开发部门员工。)
  • Set the Criteria property to [Department.Title] = ‘Development Department’.(将Criteria属性设置为[Department. Title]=‘Development Company’。)
    在这里插入图片描述

Criteria properties use Criteria Language Syntax.
条件属性使用条件语言语法。

You can also construct a filter criteria in the Filter Builder dialog. To open this dialog, click the ellipsis button to the right of the Criteria value.
您还可以在Filter Builder对话框中构建过滤条件。要打开此对话框,请单击Criteria值右侧的省略号按钮。
在这里插入图片描述

3.Add another child node to the Filters node and specify the following properties:
将另一个子节点添加到过滤器节点并指定以下属性:

  • Set the Id property to Developers.(将Id属性设置为Developers。)
  • Set the Criteria property to [Position.Title] = ‘Developer’.(将Criteria属性设置为[Position. Title]=‘Developer’。)
    在这里插入图片描述

4.Add one more child node to the Filters node and set the Id property to All Employees. Leave the Criteria property empty. This item will display all Employee objects in the List View.
将另一个子节点添加到过滤器节点并将Id属性设置为所有员工。将Criteria属性留空。此项将在列表视图中显示所有员工对象。
在这里插入图片描述

5.For the Filters node, set the CurrentFilter property to Developers. This way the Employee List View initially displays only those objects whose Position property is set to Developer.
对于过滤器节点,将货币过滤器属性设置为开发者。这样,员工列表视图最初只显示那些位置属性设置为开发者的对象。
在这里插入图片描述

6.Run the application and check that the SetFilter Action is available:
运行应用程序并检查SetFilter Action是否可用:

ASP.NET Core Blazor
在这里插入图片描述

Windows Forms
在这里插入图片描述

Set a Static Filter in the Model Editor(在模型编辑器中设置静态过滤器)

The Model Editor allows you to apply a static filter to List View records. This way, the List View initially displays only those records that fit a specified criteria and the application’s UI doesn’t have a filter Action.
模型编辑器允许您对列表视图记录应用静态过滤器。这样,列表视图最初只显示那些符合指定条件的记录,并且应用程序的UI没有过滤器操作。

1.In the MySolution.Module project, open the Model.DesignedDiffs.xafml file in the Model Editor. Navigate to the Views | MySolution.Module.BusinessObjects | Employee | Employee_ListView node. Set its Criteria property to Position.Title = ‘Developer’.
在MySolutions. Module项目中,在Model Editor中打开Model.DesignedDiffs.xafml文件。导航到视图|MySolutions.Module.BusinessObjects|员工|Employee_ListView节点。将其Criteria属性设置为Position.Title=‘Developer’。
在这里插入图片描述

2.Run the application and check that the Employee List View displays only developers:
运行应用程序并检查员工列表视图是否仅显示开发人员:

ASP.NET Core Blazor
在这里插入图片描述

Windows Forms
在这里插入图片描述

Set a Filter in Code(在代码中设置过滤器)

You can create filters that cannot be disabled in the application UI nor in the Model Editor.
您可以创建无法在应用程序UI或模型编辑器中禁用的过滤器。

1.In the Solution Explorer, right-click the Controllers folder in the MySolution.Module project, and choose Add DevExpress Item | New Item… to invoke the Template Gallery.
在解决方案资源管理器中,右键单击MySolutions. Module项目中的Controller文件夹,然后选择Add DevExpress Item|New Item…以调用模板库。

2.Select the XAF Controllers | View Controller Visual Studio template. Specify FilterListViewController as the new item’s name and click Add Item.
选择XAF控制器|查看控制器Visual Studio模板。将FilterListViewController指定为新项目的名称,然后单击添加项目。

3.In the autogenerated FilterListViewController.cs file, inherit the controller from the ObjectViewController<ViewType, ObjectType>:
在自动生成的FilterListViewController. cs文件中,从ObjectViewController<ViewType,ObjectType>继承控制器:

C#

using DevExpress.Data.Filtering;
using DevExpress.ExpressApp;
using MySolution.Module.BusinessObjects;
// ...
public partial class FilterListViewController : ObjectViewController<ListView, Employee> {
    public FilterListViewController() {
        InitializeComponent();
    }
    // ...
}

4.Override the OnActivated method:
覆盖OnActivated方法:

C#

public partial class FilterListViewController : ObjectViewController<ListView, Employee> {
    // ...       
    protected override void OnActivated() {
        base.OnActivated();
        //Specify a filter criteria.
        View.CollectionSource.Criteria["Developers"] = CriteriaOperator.FromLambda<Employee>(c => c.Position.Title == "Developer");
    }
    // ...
}

5.Run the application and check the filter in the Employee List View.
运行应用程序并检查员工列表视图中的过滤器。

Next Lesson(下一课)

Group List View Data
组列表查看数据

  • 11
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

thomastang200912_126

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值