SapUi5 表多重过滤器 [英] SapUi5 Table Multiple Filter

查看:28
本文介绍了SapUi5 表多重过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 sap.ui.table.Table 开发 sap ui5 应用程序.

I'm developing a sap ui5 application using sap.ui.table.Table.

我需要基于多个字符串应用过滤器.例如,如果用户输入是一个数组,如:

I need to apply a filter based on multiple strings. For example, if the user input is an array like:

["Stack", "Overflow"]

我需要:

  1. 通过"Stack"过滤所有表格字段;
  2. 通过"Overflow"过滤1点的结果;
  1. Filter all table fields by "Stack";
  2. Filter the result of point 1 by "Overflow";

结果将是具有 "Stack""Overflow" 的所有行,无论字段如何.

the result will be all rows that have "Stack" and "Overflow", no matter the field.

有人有解决办法吗?

推荐答案

根据 sap.ui.model.Filter 文档,您可以基于过滤器信息对象或从先前创建的过滤器数组创建过滤器.这允许我们执行以下操作:

As per the sap.ui.model.Filter documentation, you can create a filter either based on a filter info object, or from an array of previously created filters. This allows us to do the following:

  • 为第一个值创建过滤器(例如堆栈")
  • 为第二个值创建过滤器(例如溢出")
  • 创建一个包含这两个值的过滤器,并使用它来过滤表.

让我们看看一些代码.

// We will only display rows where ProductName contains 
// "Stack" AND CustomerName equals "Overflow"

var oFilterForProductName,
    oFilterForCustomerName,
    aArrayWhichContainsBothPreviousFilters = [],
    oFilterToSetOnTheTable;

var sValueToFilterTheProductNameOn = "Stack",
    sValueToFilterTheCustomerNameOn = "Overflow";

var sKeyForProductNameInTheTableModel = "ProductName",
    sKeyForCustomerNameInTheTableModel = "CustomerName";

var oTableToFilter = this.byId("myTableId");

// Step 1: create two filters
oFilterForProductName = new sap.ui.model.Filter(
    sKeyForProductNameInTheTableModel, 
    sap.ui.model.FilterOperator.Contains, 
    sValueToFilterTheProductNameOn);
oFilterForCustomerName = new sap.ui.model.Filter(
    sKeyForCustomerNameInTheTableModel, 
    sap.ui.model.FilterOperator.EQ, 
    sValueToFilterTheCustomerNameOn);

// Step 2: add these two filters to an array
aArrayWhichContainsBothPreviousFilters.push(oFilterForProductName);
aArrayWhichContainsBothPreviousFilters.push(oFilterForCustomerName);

// Step 3: create a filter based on the array of filters
oFilterToSetOnTheTable = new sap.ui.model.Filter({
    filters: aArrayWhichContainsBothPreviousFilters,
    and: true
});

oTableToFilter.getBinding("items").filter(oFilterToSetOnTheTable , sap.ui.model.FilterType.Application);

希望这会有所帮助.如果您有任何问题,请告诉我.

Hope this helps. Let me know if you have any questions.

克里斯

这篇关于SapUi5 表多重过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆