3
votes

I want my SAPUI5 ODataModel to send OData requests of the form

https://<my-server>/<my-service>/<my-resource>?search='lalaland'

There are tons of examples how to add a filter with model.filter(new Filter(...)); but this is not what I want. Filtering means I directly address a certain property with a certain comparator. Searching means I address the resource in general and let the OData service decide which properties to search, and how.

The one thing that seems to be possible is:

model.bindRows(..., { "customData": {"search": "lalaland"}});

But this is also not what I want because that sets the search term once when the model is created, but cannot update it later on when the user enters.

Funnily, SAPUI5's own implementation of the SmartTable performs exactly the kind of query I want - but doesn't reveal a possibility how I could do that without a SmartTable.

3

3 Answers

1
votes

Found one solution:

oList = this.byId("list"); // or oTable
oBindingInfo = oList.getBindingInfo("items"); // or "rows"
if (!oBindingInfo.parameters) {
  oBindingInfo.parameters = {};
}
if (!oBindingInfo.parameters.custom) {
  oBindingInfo.parameters.custom = {};
}
oBindingInfo.parameters.custom.search = sValue;
oList.bindItems(oBindingInfo);

However, I don't specifically like the bindItems part. Looks a bit over-the-top to require this to re-bind the whole entity set again and again. So leaving this question open in case somebody has a better idea.

0
votes

You can use on bindItems or bindRows depending what control is, something like this:

oList = this.byId("list"); 
oList.bindItems({path: '/XXXX', parameters : {custom: {'search':'searchstring'}}})
0
votes

Why does it has to be $search and not $filter?

The OData V4 Tutorial in SAPUI5's Demo Kit uses

onSearch : function () {
            var oView = this.getView(),
                sValue = oView.byId("searchField").getValue(),
                oFilter = new Filter("LastName", FilterOperator.Contains, sValue);

            oView.byId("peopleList").getBinding("items").filter(oFilter, FilterType.Application);
        },