简体   繁体   English

筛选表检查多列

[英]Filtering table checks multiple columns

I have a table with several columns and also a search bar at the top that performs the function below. 我有一个包含多列的表格,并且在顶部还有一个搜索栏,它执行下面的功能。 I thought that given the code below, only the "field1" column would be searched, but in fact if I search for a term in another column it will show up. 我认为给定下面的代码,将仅搜索“ field1”列,但实际上,如果我在另一列中搜索术语,它将显示出来。 Now my problem is there is a new column I'm adding that I'd like to add to this search. 现在我的问题是,我要添加一个新列,我想添加到此搜索中。 I try adding it to the filters array like this 我尝试像这样将其添加到filters数组中

new filter("fieldIWant",FilterOperator.Contains,sValue)

but it won't work. 但它行不通。 I made the column invisible because I don't want it displayed on the table but I want it to still be searchable. 我使该列不可见,因为我不希望该列显示在表中,但我希望它仍可搜索。 I guess my first question is why the search bar works for multiple fields when I only specified "field1". 我想我的第一个问题是,当我仅指定“ field1”时,为什么搜索栏可用于多个字段。

onSearchPressed : function() {
    var sValue = this.byId("searchField").getValue();
    var aFilters = [];

    var filters = [new Filter("field1","EQ",sValue)];
    aFilters = filters;
    var oFilter = new Filter({aFilters : filters});
    if (!aFilters) {
        aFilters = [];
    }
    this._aSearchFilters = aFilters;
    if (this._aSelectFilters)   {
        aFilters = aFilters.concat(this._aSelectFilters);
    }
    if (this._aQuickFilters)    {
        aFilters =aFilters.concat(this._aQuickFilters); 
    }

    var oBinding = this.byId("catalogTable").getBinding("items");
    oBinding.filter(aFilters );
},

NOTE: This was prewritten code and isn't mine so I don't want to make any major changes but rather understand why it works like it does. 注意:这是预先编写的代码,不是我的,因此我不想进行任何重大更改,而是想知道为什么它能像它那样工作。 _aSelectFilters and _aQuickFilters do not contain any searches for columns, they're for something else. _aSelectFilters_aQuickFilters不包含对列的任何搜索,它们用于其他内容。

You may want to check your metadata file; 您可能要检查元数据文件; look at the sap:filterable tag. 看一下sap:filterable标签。 If it's set to false and you are still able to filter then you have to check the backend. 如果将其设置为false并且仍然可以过滤,则必须检查后端。 If they are set to true then the way you've done it using multiple new Filter(...) works fine. 如果将它们设置为true,则使用多个new Filter(...)可以正常工作。

Hope this will help you 希望这个能对您有所帮助

onSearchPressed : function() { 
var    sValue = this.byId("searchField").getValue();
 var        aFilters = [];
var searchFilter1 = new     sap.ui.model.Filter("key_of_column1",sap.ui.model.FilterOperator.Contains, sValue);
var searchFilter2 = new sap.ui.model.Filter("key_of_column2",sap.ui.model.FilterOperator.Contains, sValue);
var searchFilter3 = new sap.ui.model.Filter("key_of_column3",sap.ui.model.FilterOperator.Contains, sValue);
//Add as many columns you have
aFilters.push(searchFilter1);
aFilters.push(searchFilter2);
aFilters.push(searchFilter3);

var table = this.byId("catalogTable");
       table.getBinding("items").filter(aFilters);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM