2017-01-20 9 views
0

私はsap.ui.table.Tableを使ってsap ui5アプリケーションを開発しています。SapUi5テーブル複数のフィルタ

複数の文字列に基づいてフィルタを適用する必要があります。例えば、ユーザ入力は、のような配列の場合:

["Stack", "Overflow"] 

は私が必要:"Stack"全テーブル項目

  1. フィルター。
  2. ポイント1の結果を"Overflow"でフィルタリングします。

結果はフィールドに関係なく"Stack""Overflow"のすべての行になります。

解決方法はありますか?

+0

[複数のフィールドに "または"と "と"の条件でフィルタリングする](https://stackoverflow.com/questions/42433200/filter-with-or-and-and-conditions-on-multiple-フィールド) – boghyon

答えて

1

sap.ui.model.Filter documentationによれば、フィルタ情報オブジェクトに基づいて、または以前に作成されたフィルタの配列からフィルタを作成できます。どのフィルタを作成します

  • 第二の値(例えば「オーバーフロー」)のためのフィルタを作成
    • 最初の値(例えば「スタック」)のためのフィルタを作成します。これは、私たちは次のことを行うことができますこれらの値の両方を含み、テーブルをフィルタリングするために使用します。

    いくつかのコードを見てみましょう。

    // 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); 
    

    これが役立ちます。ご質問がある場合はお知らせください。

    クリス

  • 0

    、それはあなたのために役に立つかもしれループのためにその配列を渡すなどのフィルターを通過し、

    var tableId = this.byId("oTable"); 
    for(var i=0;i < array.length ; i++) 
    { 
        oTable.getBinding().filter(new sap.ui.model.Filter("", sap.ui.model.FilterOperator.Contains, array[0])); 
    
    } 
    

    してください。

    関連する問題