-1

The filter using below code is not working. I created an application using a template from Web IDE and then bound OData to the list in XMLView, applying filter on search.

View:

<SearchField liveChange="onSearch" id="master1SearchField" search="onSearch"/>  
<List id="master1List" items="{path:'/DetailsSet'}">
    <items>
        <ObjectListItem id="master1ListItem">
            <attributes>
                <ObjectAttribute text="{Name}"/>                            
            </attributes>
        </ObjectListItem>
    </items>
</List>

Controller:

onSearch : function(oEvent) {
    var sFilteredValue = oEvent.getSource().getValue();
    var oFilter = new sap.ui.model.Filter("Name", sap.ui.model.FilterOperator.Contains, sFilteredValue);
    var oElement = this.getView().byId("table");
    var oBinding = oElement.getBinding("items");
    oBinding.filter([oFilter]);             
}
Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
user1862322
  • 87
  • 2
  • 11
  • Are you applying the filter on the correct control? The ID of your `oElement` is `"table"` whereas the list has the ID `"master1List"`. – Boghyon Hoffmann Feb 21 '17 at 23:13
  • 1
    Possible duplicate of [Filter with "orβ€œ and "and" conditions on multiple fields](https://stackoverflow.com/questions/42433200/filter-with-or-and-and-conditions-on-multiple-fields) – Boghyon Hoffmann Dec 07 '17 at 21:52

2 Answers2

1

You need to get binding of the items on which the filter need to be applied.

var oElement = this.getView().byId("master1List"); 

should resolve the issue.

Meghana
  • 41
  • 4
-1

Try to force an update of the control after setting the filter:

oBinding.refresh(true);
FelixSFD
  • 6,052
  • 10
  • 43
  • 117
M. Huebler
  • 69
  • 1
  • 9