docs

Filtering

The OData V4 Model supports server-side filtering on lists.

To use server-side filtering, set the operation mode to sap.ui.model.odata.OperationMode.Server. This can be done as follows:

Example: Operation mode set in manifest.json for the model


"models" : {
    "" : {
        "dataSource" : "default",
        "settings" : {
            "operationMode" : "Server",
            "synchronizationMode" : "None"
        }
    }
}

Example: Operation mode set as binding parameter for a specific list binding


<Table growing="true" growingThreshold="5" id="Equipments"
    items="{
            path : '/Equipments',
            parameters : {
                $$operationMode : 'Server',
                $filter : 'Category eq \'Electronics\'',
                $select : 'Category,EmployeeId,ID,Name'
            }
        }">

The ODataListBinding allows to set static and dynamic filters:

The ODataListBinding combines the dynamic filter and static filter with a logical AND.

Examle: Dynamic and static filters


<Table growing="true" growingThreshold="5" id="Equipments"
    items="{
            path : '/Equipments',
            parameters : {
                $$operationMode : 'Server',
                $filter : 'Category eq \'Electronics\'',                             <-- static filter
                $select : 'Category,EmployeeId,ID,Name'
            },
            filters : {                                      <-- dynamic filter initial value
                path : 'EmployeeId',
                operator : 'GE',
                value1 : '0000'
            }
        }">

The example above filters the Equipments entity set by Category (static filter) and EmployeeId (dynamic filter, initial value).


Filtering with Any, All, NotAny, and NotAll

The OData V4 model supports the Lambda Operators any and all as defined in Section 5.1.1.10 of the OData Version 4.0. Part 2: URL Conventions specification. These operators and their negated forms are represented using sap.ui.model.Filter objects with filter operators sap.ui.model.Filter.Any, sap.ui.model.Filter.All, sap.ui.model.Filter.NotAny, and sap.ui.model.Filter.NotAll.

Example:

// "Filter" and "FilterOperator" required from modules "sap/ui/model/Filter" and "sap/ui/model/FilterOperator"
new Filter({
    // the path of the collection for which the condition needs to be evaluated
    path: "Trips",
    // one of the filter operators listed above
    operator: FilterOperator.Any,
    // any OData identifier which is a variable for the current element of the collection referenced by the path
    variable: "trip",
    // the filter condition; the path of the nested filter contains the variable as prefix to reference the current element of the collection
    condition: new Filter("trip/Budget", FilterOperator.GT, 1000)
});

The path of the filter object is the path of the collection for which the boolean condition needs to be evaluated. The variable can be any OData identifier, and it needs to be part of the path of a nested filter condition.


Filter Operator Any

The filter operator Any applies the boolean filter condition to each member of the collection referenced by path. If the condition is true for at least one member of the collection, the Any filter matches. The filter with the Any operator without a filter condition matches only if the collection referenced by path is not empty.

Example 1: Retrieve all individuals who have at least one trip

oListBinding.filter(
    new Filter({
        path: "Trips",
        operator: FilterOperator.Any
    })
);

The resulting request is: https://host/service/People?$filter=Trips/any()

Example 2: Retrieve all individuals who have at least one trip with a budget exceeding 1000

oListBinding.filter(
    new Filter({
        path: "Trips",
        operator: FilterOperator.Any,
        variable: "trip",
        condition: new Filter("trip/Budget", FilterOperator.GT, 1000)
    })
);

The resulting request is: https://host/service/People?$filter=Trips/any(trip:trip/Budget gt 1000)


Filter Operator NotAny

The filter operator NotAny applies the boolean filter condition to each member of the collection referenced by path. If the condition is true for none of the members of the collection, or if the collection is empty, the NotAny filter matches.

Example 1: Retrieve all individuals who have no trips at all

oListBinding.filter(
    new Filter({
        path: "Trips",
        operator: FilterOperator.NotAny
    })
);

The resulting request is: https://host/service/People?$filter=not Trips/any()

Example 2: Retrieve all individuals who have no trips with the status “Rejected”

oListBinding.filter(
    new Filter({
        path: "Trips",
        operator: FilterOperator.NotAny,
        variable: "trip",
        condition: new Filter("trip/Status", FilterOperator.EQ, "Rejected")
    })
);

The resulting request is: https://host/service/People?$filter=not Trips/any(trip:trip/Status eq 'Rejected')


Filter Operator All

The filter operator All applies the boolean filter condition to each member of the collection referenced by path. If the condition is true for all members of the collection, the All filter matches.

Example: Retrieve all individuals whose trips are all named “Walldorf”

oListBinding.filter(
    new Filter({
        path: "Trips",
        operator: FilterOperator.All,
        variable: "trip",
        condition: new Filter("trip/Name", FilterOperator.EQ, "Walldorf")
    })
);

The resulting request is: https://host/service/People?$filter=Trips/all(trip:trip/Name eq 'Walldorf')


Filter Operator NotAll

The filter operator NotAll applies the boolean filter condition to each member of the collection referenced by path. If the condition is not true for any member (that is, at least one member) of the collection, the NotAll filter matches.

Example: Retrieve all individuals whose trips do not all have the name “Walldorf” (i.e. for whom at least one trip has a different name)

oListBinding.filter(
    new Filter({
        path: "Trips",
        operator: FilterOperator.NotAll,
        variable: "trip",
        condition: new Filter("trip/Name", FilterOperator.EQ, "Walldorf")
    })
);

The resulting request is: https://host/service/People?$filter=not Trips/all(trip:trip/Name eq 'Walldorf')

Related Information

sap.ui.model.odata.OperationMode.Server